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?
Asked
Active
Viewed 1,196 times
-1
-
1Are 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 Answers
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

Joris Coenen
- 56
- 7
-
I think this would only happen if the userscript is using the version of jquery on the host page rather that its own. – Andy Oct 30 '14 at 11:07
-
-
if the page is not using jquery nothing happens, i don't know if the version has to be the same, answer editted – Joris Coenen Oct 30 '14 at 11:20