I try to make a jQuery.ajax call:
jQuery("#search_form").live("submit", function() {
search_nr = jQuery("#search_input").val();
jQuery.ajax({
url: '/modules/mod_findarticle/process.php',
data: "search_nr="+search_nr,
async: true,
'success': function(data) {
alert(data);
},
'error': function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.status+", " + jqXHR.statusText+", "+textStatus+", "+errorThrown);
}
});
});
In return i always get an alert with “0, error, error,” message. Everything’s fine with async=false.
I know that with asynchronous call the script finish work before any actual data is recieved but what can be done to avoid this?
Problem solved thanks to user mccannf :
The data was submitted twice by triggering the ‘submit’ event on the form, so the script always stopped processing data before the second call. Replacing
function()in.live(...)withfunction(e) {e.preventDefault; ... }disables the default submit action and hence does the trick!