-1

I have a userscript that I need to run EVERY time ANY page to which the userscript is attached is modified by AJAX. Is there any method to listen the XMLHttpRequest-s?

Andy
  • 61,948
  • 13
  • 68
  • 95
MPMOZ
  • 1
  • 2
  • 1
    Are you using jQuery for your Ajax requests? You could use the http://api.jquery.com/ajaxcomplete/ method. – Andy Oct 30 '14 at 10:44
  • @Andy I want to listen all Ajax request, not only mine. It's an userscript which should run on all pages in the web. – MPMOZ Oct 30 '14 at 10:53

2 Answers2

0

I cannot tell exactly what you are looking for without the code you are using, but I hope this is useful.

var request = new XMLHttpRequest();
request.open("GET", "http://yoururl");
request.onload = function () {
    if (this.status >= 200 && this.status < 400) {
        // HERE RUN THE FUNCTION YOU WANT TO RUN AGAIN
    }
};
request.send();
Urielzen
  • 476
  • 7
  • 17
  • I dont want to create a new request. In example i want ot run script every time i change page in Google. – MPMOZ Oct 30 '14 at 11:05
0

As far as I get it you want a certain script to run everytime the page is modified by an ajax request.

$( document ).ajaxComplete(function() {
  console.log("an ajax request was completed);
});    

if you replace the console.log with your code, it will run everytime when an ajax request is completed on the document (webpage).

to check it without using jquery this should work:
https://stackoverflow.com/a/18259603/4194167

also don't forget to add

@run-at document-start

to your userscript, it needs to be loaded before the webpage is running.

Community
  • 1
  • 1