I'm having some problems with a jQuery control we made. Suppose you have a dropdownlist that allows you to enter the ID of the item you're looking for, and when you press ENTER or lose focus in a textbox it validates via jQuery that the ID you entered is correct, showing an alert if it doesn't.
The thing is that when an ordinary user enters an invalid value in it and loses focus by pressing the submit button, the jQuery post returns after the submit of the form has been sent.
Is there any way that I can check if there's any Async request processing by jQuery so that I do not allow the form submit?
You need to attach . ajaxStop() to the document to detect when all AJAX requests get completed. Use global: false option in the AJAX requests if you don't want to detect by . ajaxStop() .
If you are using xmlhttp object for ajax call then when xmlhttp. readyState==4 then it is consider as ajax request is completed.
get() executes an Ajax GET request. The returned data (which can be any data) will be passed to your callback handler. $(selector). load() will execute an Ajax GET request and will set the content of the selected returned data (which should be either text or HTML).
$.active
returns the number of active Ajax requests.
More info here
You could use ajaxStart and ajaxStop to keep track of when requests are active.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With