backbone.js ã angularjs ã vue.jsãªã©ãã¯ã©ã¤ã¢ã³ããµã¤ãMVCã§http ãªã¯ã¨ã¹ãæã«ã¤ãã³ããåå¾ããã
é常ã®WEBãµã¤ãã§ããã°httpéä¿¡ã¯1åã ããªã®ã§onloadã§å¤§ä¸å¤«ã§ããã
backbone.js ã angularjs ã vue.jsãªã©ãã¯ã©ã¤ã¢ã³ããµã¤ãMVCã§ã¯éåæã§httpéä¿¡ãèµ°ãçºã
ä¾ãã°ã¯ã©ã¤ã¢ã³ããµã¤ãã ãã§ãã»ãã·ã§ã³ã®ã¿ã¤ã ã¢ã¦ããªã©ãæ¤ç¥ããã®ãé£ããã§ãã
ãããã£ãã¤ãã³ãã¯ãªããããªã®ã§ããã®å ´åXMLHttpRequestã®callbackãããã¯ãã¦é¢æ°ãç»é²ãã¾ãã
jQueryã§ajaxCompleteã使ãã®ãæãªã®ã§ããã$.ajax使ã£ã¦ãªãå ´åãããã®ã§ããã¡ãã使ã£ã¦ã¿ã¾ããã
function addXMLRequestCallback(callback){ var oldSend, i; if( XMLHttpRequest.callbacks ) { // we've already overridden send() so just add the callback XMLHttpRequest.callbacks.push( callback ); } else { // create a callback queue XMLHttpRequest.callbacks = [callback]; // store the native send() oldSend = XMLHttpRequest.prototype.send; // override the native send() XMLHttpRequest.prototype.send = function(){ // process the callback queue // the xhr instance is passed into each callback but seems pretty useless // you can't tell what its destination is or call abort() without an error // so only really good for logging that a request has happened // I could be wrong, I hope so... // EDIT: I suppose you could override the onreadystatechange handler though for( i = 0; i < XMLHttpRequest.callbacks.length; i++ ) { XMLHttpRequest.callbacks[i]( this ); } // call the native send() oldSend.apply(this, arguments); } } } // e.g. addXMLRequestCallback( function( xhr ) { console.log( xhr.responseText ); // (an empty string) }); addXMLRequestCallback( function( xhr ) { console.dir( xhr ); // have a look if there is anything useful here });
- ajaxCompleteã®å ´åã¯ãããªæã
$(function(){ $(document).ajaxComplete(function() { console.log('ajaxéä¿¡ãçºçããã'); }); })