I can pass a parameter for the redirect url and a user id in a browser, this is an intranet application btw. So you can paste the address such as “http://intranetapp?redirect_url=http://crapola&userid=xxxxxxx. It redirects you to that url and provides additional information for the user id, which is what i want to obtain for several hundred users. The information is returned as part of parameters where you get redirected. Is there any way to call (GET request) this with ajax or related method of jquery and read the returned url and parameters instead of just getting the returned html?
Share
Chris, if I understand correctly, what you want to do is moderately tricky.
I have never needed to do this sort of thing but know in principle that it involves an unusual type of ajax request – namely a “HEAD” request, allowing the redirect url (and other meta data) to be inspected without receiving the main part of the HTTP response (the body).
Your intranet server should handle HEAD requests (they are at least as safe as GETs) but not necessarily. If not, then have a word with your server admins. If you are the server admin then have a root around in the
httpd.conffile and/or the appropriate.htaccessfile (assuming Apache).As with all types of ajax, the code is also tricky because parts of it need to run asynchronously (when an HTTP response from the server arrives back). To assist in this, jQuery’s Deferreds/Promises can be (liberally) employed.
Your main worker function (still if I understand correctly) will be something like this :
Note that, because the ajax is asynchronous, we return a promise not the results we actually want; they arrive later, packaged in the javascript plain object
q.Here’s how to test
getUserParams():Your intended use, with hundreds of urls, will be something like this :
You may also want to do something when responses to ALL ajax requests have been received. If so then the additional code will look like this :
Part tested (the code runs but I don’t have the means to test the redirect or handling of the
Locationheader).You will need to fine-tune [some subset of] the code to make precise use of the user data in the
qobject, and to handle errors appropriately.