-1

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.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
klis87
  • 478
  • 1
  • 4
  • 18

2 Answers2

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
  • Thanks, but I tried this, it is not AJAX request, but long-polling – klis87 Mar 04 '15 at 13:14
  • What do you mean? What's the code that triggers the call? – Jeremy Thille Mar 04 '15 at 13:15
  • 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
  • So, if they are XHR request, why isn't my answer relevant? – Jeremy Thille Mar 04 '15 at 14:13
  • 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