Friday, November 27, 2009

Re: [jQuery] Returning Value Of aa .POST

$.ajax(), $.get(), $.post(), $.load(), none of these methods return the result of the AJAX call, because they're meant to be asynchronous (the first "A" in AJAX), which means they're working behind the scene, detached from the place they've been called. If they were not they would freeze the interface until the call ends, and most of the time nobody wants that. In order to execute something after the call succeeds you have to use callbacks :
http://docs.jquery.com/Ajax/jQuery.post#urldatacallbacktype

Michel Belleville


2009/11/26 Nuclear <nymphonics@gmail.com>
function ajax_post_var(url, event_id)
{
       var info = $.post(url).responseText;
       alert(info);
       if (event_id == '1')
       {
               do something with info...
       }
       ...more if's here...
}

Why does info show undefined... I'd like to be able to use the
returned value for something else.

No comments: