In my javascript application(using prototype), I need some info from a third party server an this server sometimes requires web interaction with the user, and for that reason it sends 302 http code with a new URL in the Location header. What I want is to capture this new URL to open it in a separate window, however the method getHeader(‘Location’) is always returning null. Any Idea??? This is simplified version of my code:
UPDATE = function(){
new Ajax.Request(proxy_url,{
method: 'post',
parameters: "p1=1&p2=2",
on302: function(response){
OpenURLfromLocation(response);
},
onSuccess: function(transport){
alert("OK");
}
});}
OpenURLfromLocation = function(response){
alert(response.getHeader('Location'));
}
The ajax proxy is working properly and I can see on firebug that it behaves correctly until it tries to recover the location from the header.
It’s been a while since I’ve used Prototype, but on the actual XMLHttpRequest object, the method name is
getResponseHeader. However, if you control the server’s response, why not just return the new URL in the response body?As a side note, if you’re adding “location” to the response header being sent back from the server, the convention is to prepend anything that you add to the headers with an “X-“, so you would have “X-Location”