I’m using PhantomJS with jQuery and I’m wondering if it’s possible to capture an XMLHttpRequest as it’s passed to the browser, without initiating the POST/GET yourself.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are simple jQuery functions that will let you modify AJAX requests before they are sent, but they only target AJAX requests initiated by jQuery. To catch all AJAX requests on a page, use the following basic JS-only way:
You could also rewrite the XHR send() function:
Basically, this code needs to be the FIRST code that runs on your page. All subsequent XHR requests will go through the rewritten function(s), allowing you to change any parameters, etc.
Note: if you wish to target some versions of IE, you need to implement similar code for the ActiveXObject that IE uses for AJAX.