How to intercept every AJAX request from a webpage
Asked Answered
T

3

7

I need the way to intercept all ajax requests maded from page. So i need some wrapper to add my data to all users requests.

Turkic answered 8/7, 2010 at 10:57 Comment(2)
How are you making these requests?Concoff
How about using this library? github.com/slorber/ajax-interceptorBelen
T
5

Huh... i made this work))) with help of this topic Extending an ActiveXObject in javascript i made script that intercept all ajax requests no matter what framework or browser do user use.

You can look at it here: Script

Turkic answered 9/7, 2010 at 19:46 Comment(0)
S
0

I dont think you can get this out of the box .
What you need here is a little restructuring of your client side code [ You should have already done that , but it is never too late :) ] .
Make a function that has the responsibility of interacting with server . Use this to make ALL your server requests and get data . After that whenever you need to do something at a application level ( like maybe caching data to avoid server side trip ) you can do in this function .
So something like

xhr_request( url , callback_function, params ) ;
// where xhr_request is your custom function that takes care of server interaction .
Subchaser answered 8/7, 2010 at 11:8 Comment(0)
D
0

I'm looking for the same thing i think i want to modify ajax reponse on the fly i find this i'll tell you but it's hard for a script kiddies like me

See the Enterprise JQuery article Mock Your Ajax Requests with Mockjax for Rapid Development.

Dominickdominie answered 19/8, 2012 at 22:48 Comment(1)
This is not for mocking but for intercepting requests from any script on the page. For example you need to add debug for each request in console. As for me, i was using to make online proxy, so i was need possibility to change all request to my proxy server) As for mocking you should use something more simpler)Turkic

© 2022 - 2024 — McMap. All rights reserved.