Intercept all ajax calls?

前端 未结 4 1199
执笔经年
执笔经年 2020-11-27 03:32

I\'m trying to intercept all AJAX calls in order to check if that AJAX response contains specific error code that I send as JSON from my PHP script (codes: ACCESS_DENIED, SY

4条回答
  •  温柔的废话
    2020-11-27 03:43

    The raw javacript code to intercept ajax calls:

    (function(send) {
        XMLHttpRequest.prototype.send = function(body) {
            var info="send data\r\n"+body;
            alert(info);
            send.call(this, body);
        };
    })(XMLHttpRequest.prototype.send);
    

    The jQuery code to intercept ajax:

    $.ajaxSetup({
        beforeSend: function (xhr,settings) {
            alert(settings.data);
            alert(settings.url);
        }
    });
    

    Reference: http://myprogrammingnotes.com/intercept-ajax-calls-jquery.html

提交回复
热议问题