javascript - How to run a function when any XMLHttpRequest is complete? -


i'm working on project has several scripts cannot change. these scripts update page via ajax. when update complete need run code.

is there event fires when xmlhttprequest complete? (or xmlhttprequest state change?).

unfortunately cannot access specific xmlhttprequest object used make request.

thanks,

without jquery, can hook open method attach listener each xhr object's readystatechange events @ time xhr object opened. ensure following code runs before ajax occurs:

// save real open var oldopen = xmlhttprequest.prototype.open;  function onstatechange(event) {     // fires on every readystatechange ever     // use `this` determine xhr object fired change event }  xmlhttprequest.prototype.open = function() {     // when xhr object opened, add listener readystatechange events     this.addeventlistener("readystatechange", onstatechange)      // run real `open`     oldopen.apply(this, arguments); } 

alternatively, if care successful load events, can listener event instead of readystatechange.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -