javascript - How to inspect the successful result of a jQuery AJAX request and abort the jQuery.load() before it inserts the content? -
i using jquery.load()
method make ajax request , insert content page.
i able add kind of global handler inspect result of successful ajax request, , optionally call global error handler based on data returned.
i have been able achieve 'normal' jquery.get()
requests using $.ajaxprefilter()
override provided 'success' method 1 inspects request. (found on stackoverflow answer: https://stackoverflow.com/a/6373965)
$.ajaxprefilter(function( options, originaloptions, jqxhr ) { var originalsuccess = options.success; options.success = function (data) { if(haserrors(data)) { //forward error event handler or redirect login page example } else { if (originalsuccess != null) { originalsuccess(data); } } }; });
my problem method not work ajax requests fired jquery.load()
method. i've looked in jquery source , it's doing this:
jquery.ajax({ .. }) .done(function(responsetext) { // inserts html dom. }) .complete(callback);
is there anyway inspect result of successful .ajax()
method , prevent deferred .done()
function being fired?
ideally, i'd solution can slot .ajaxprefilter()
method above behaviour global entire site.
on server side code, should able display success response or data passed. can use firebug console (for firefox) display ajax results. alternatively can use chrome developer tools. in console, activate logxmlhttprequests right clicking on it.
the network inspector of firebug , chrome developer tools displays ajax responses in xhr tab.
Comments
Post a Comment