[EMAIL PROTECTED] schrieb: > Anyone ever successfully sent data to server with MochiKit's doXHR > function?
I have. See example below (uses the RUZEE events JS library <http://www.ruzee.com/blog/ruzeeevents/>, but this is of no consequence for the question at hand). /* * Show article preview received via AJAJ. */ function show_article_preview(res) { logDebug('show_article_preview called'); res = evalJSONRequest(res); if (res['error']) { update_article_preview(P({'class': 'errmsg'}, res['error'])); } else { var heading = H2({}, $('articleform_title').value); var container = DIV({}); container.innerHTML = res['preview']; /* the following method calls basically just swaps the content of a div with the preview */ update_article_preview([heading, container]); } } /* * Show error message when no article preview is available. */ function no_preview(err) { update_article_preview(P({'class': 'errmsg'}, 'No preview available')); } /* * Load article preview via AJAJ. */ function load_article_preview(e) { logDebug('load_article_preview called'); var text = $('articleform_text').value; /* do a POST XmlHttpRequest with url-encoded comment text */ var d = doXHR('/preview', { 'method': 'POST', 'sendContent': 'text=' + escape(text) + '&format=rest', headers: {"Content-Type": "application/x-www-form-urlencoded"} }); d.addCallbacks(show_article_preview, no_preview); } /* * Add a 'Preview' link/button to the comment form */ function add_previewaction() { var submit = $('submit_article'); if (submit) { var button = INPUT({ 'id': 'preview', 'type': 'button', 'class': 'submitbutton', 'value': 'Preview', 'accesskey': 'p', 'title': 'Show article preview [p]' }); submit.parentNode.appendChild(button); connect(button, 'onclick', load_article_preview); } } /* * Add callbacks on page load */ RUZEE.Events.add(window, 'domload', function() { var submit = $('submit_entry'); add_previewaction(submit); } ); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

