I'm working with asp controls and I have some dropdownlist which in selection go back to the server and do some action ( via asp ajax ) what I'm l looking for is detecting via jquery when the ajax call is starting I've tried the following call :
  $.ajaxSetup({
                    beforeSend: function (jqXHR, settings) {
                        alert("ok");
                        return false;
                    }
                });
and
also  $(document).ajaxStart(function () {
                   alert("OK");
                });
but none of this worked
well, if $(document).ajaxStart(function() {}); is not working for you,
try a bit raw js,
var oldXHR = window.XMLHttpRequest;
function newXHR() {
    var realXHR = new oldXHR();
    realXHR.addEventListener("readystatechange", function() {
        if(realXHR.readyState==1){
            alert('server connection established');
        }
        if(realXHR.readyState==2){
            alert('request received');
        }
        if(realXHR.readyState==3){
            alert('processing request');
        }
        if(realXHR.readyState==4){
            alert('request finished and response is ready');
        }
    }, false);
    return realXHR;
}
window.XMLHttpRequest = newXHR;
it should give you all the states of a ajax request and check which one works for you, and then u can remove rest of the if conditions. you can place it outside of $(document).ready(function(){});
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