I have long-polling specific problem. I would like to be able to attach event listener to document, that checks for successful long-polling request and gives me json results as return of callback function. Is it possible with jquery or pure js? The assumption is that I cannot modify any js code, only add event handler.
Asked
Active
Viewed 320 times
-1
-
If you can't change any JS code, It's going to be really hard to do with jQuery or pure JS ? – adeneo Mar 04 '15 at 12:57
-
I meant that I would like to add function to existing code, without any changes. – klis87 Mar 04 '15 at 13:02
-
Could you please post what you have tried up until now? Also, jQuery is written in JS, which means that everything that is possible with jQuery is also possible with vanilla JS :) – vladzam Mar 04 '15 at 13:03
-
Are you talking about Ajax request? – Justinas Mar 04 '15 at 13:05
-
no, Long Polling one – klis87 Mar 04 '15 at 13:14
2 Answers
0
You can use jQuery's ajaxComplete() method, that listens for any XHR (ajax requests) coming back. http://api.jquery.com/ajaxcomplete/
$( document ).ajaxComplete(function(event, xhr, settings) {
});

Jeremy Thille
- 26,047
- 12
- 43
- 63
-
-
-
I will be probably taken unseriously but I cannot find this in minified code, I tried by without success. All I can see is that in chrome developer tools in xhr tab there are get requests constantly being made every 40ms. – klis87 Mar 04 '15 at 13:28
-
-
I am not sure, it just didn't work. I have found the solution by overriding attribute of XMLHttpRequest.prototype. – klis87 Mar 04 '15 at 17:07
0
I was finally able to solve this problem, by overriding attribute of XMLHttpRequest.prototype.

klis87
- 478
- 1
- 4
- 18