Thank you for taking of your time to help me out.
Even though I sure can't be the first one having this problem, I couldn't find any good answer so far so there it goes.
Let's say I have two ASP (classic) pages.
Target1.asp which redirects to Target2.asp with response.redirect(url)
Now, I have to GET Target1.asp using async methods and you might have already figured out I am using AJAX to do so.
Problem is when I use $.ajax('method':'GET', [...]) or simply $.get('Target1.asp') and have the 'complete' callback fill a div with response content, it redirects the whole page to Target2.asp instead of filling the div.
The reason is quite simple: the div is indeed filled with content of Target1.asp. The browser still has to redirect and since a div is not like an iframe at all, the entire page is redirected.
I am almost sure you cannot control redirections directly from javascript (?).
Is there a way of handling this problem without making use of iframes?
This is what I am trying to do: Request Target1.asp with GET method using ajax, handle redirection (or something similar) so that ajax requests Target2.asp AND THEN fill the div with the final result.
Thank you.
EARLY EDIT : If you need a coded example, I can write one.
Yes,
replace response.redirect(url) with server.execute(url) or server.transfer(URL).
This will keep control of the navigation on the server and not let the browser redirect.
Here are the differences (in .NET, but it's the same IIS object so the same goes for Classic ASP)
HTH,
Erik
You should be careful to note in your question header that you are using jQuery. While, yes you are calling the Ajax method, you are not doing it manually and are instead relying on functionality that might be explicit to the library you are utilizing.
The short answer is that, no you probably cannot prevent the redirect from happening transparently as this is typically done automatically by the browser itself. The longer answer is you should probably try to do something to inspect the data you get back from your ajax response to see if it is what you expected. Of course this may be very dependent if you have any mechanism to do so with the data you are getting back or if you have any control over the server side response.
The following article on stackoverflow goes into much more detail:
How to prevent ajax requests to follow redirects using jQuery
You have a satisfactory answer, but you might also like to experiment with
myurl = "http://(a full external url)"
set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
xmlhttp.open "GET", myurl, false
xmlhttp.send ""
Response.write xmlhttp.responseText
set xmlhttp = nothing
which is what I meant by running an asp page and including the output, which is slightly different to an include file statement