Duboe Duboe - 3 days ago 5
Ajax Question

on.blur and on.click triggered prior to ajax?

I have two events and the second one triggers an Ajax call. (A click creates an input in the

<td>
which is overwritten by the success event afterwards - so the input on the blur is correct)

$(document).on("click","#"+table_id+" td",function(e)

$(document).on("blur","#"+table_id+" td input",function(e)
ajax(ajaxStatements,"update");


If I click on a
<td>
and then click on an empty space afterwards it goes as follows:

CLICK EVENT -----------

BLUR EVENT #######

AJAX EVENT +++++++

If I click on a
<td>
and then follow up with another click on another
<td>
it doesn't behave properly.

CLICK EVENT -----------

BLUR EVENT #######

AJAX EVENT +++++++

CLICK EVENT -----------

This is what I want. But then - and this is the Question - the response varies and does this:

CLICK EVENT -----------

BLUR EVENT #######

CLICK EVENT -----------

AJAX EVENT +++++++

Why does the new click-event trigger before the ajax call even if the blur event is called?

Answer

Because AJAX is asynchronous so your request and the click event is triggered simultaneously.

Try this:

$.ajax({
 async:false,
})
Comments