is it possible to catch anything that comes from the server via ajax ? I know that the ajaxComplete() fires when some ajax work completes
I would l开发者_如何学JAVAike to e.g.
alert(whichever content came from the server as a result for $.ajax, $.post, $.get)
jQuery.ajaxComplete
should do just fine.
$(document).ajaxComplete(function(event, XHR, ajaxOptions) {
var resp = XHR.responseText
? XHR.responseText
: (XHR.responseHTML
? XHR.responseHTML
: XHR.responseXML);
alert(resp);
});
The documentation says that the response will be in XHR.responseHTML
or XHR.responseXML
, but I suspect the latter might be a typo, since my empirical test show that the two members present are XHR.responseText
and XHR.responseHTML
.
But then again, my tests weren't exhaustive and didn't take in account the mime type returned by the server, so don't take my word for it, as I might be horribly mistaken.
Also this example blatantly ignores the status code returned and should by no means be taken as a good example, merely as a possible starting point.
See an ugly running demo
精彩评论