Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to get Response Header location from jQuery Get? WordPress

1 down vote favorite


So I am trying to get the location from a header response via jQuery get. I tried using getResponseHeader('Location') and getAllResponseHeaders() but they both seem to return null.

Here's my current code

$.ajax({
type: "GET",
url: 'http://searchlight.cluen.com/E5/Login.aspx?URLKey=uzr7ncj8)',
complete: function(xhr) {
alert(xhr.getAllResponseHeaders());
}
});

I have tried doing so with both the success or not success method as well

Answers (7)

2012-07-02

Duncan O'Neill answers:

Hi,

I'm not a jQuery ninja by any means, but have a couple of suggestions;

- give the url to the site / page in question
- try [[LINK href="http://getfirebug.com/"]]firebug[[/LINK]]. Clicking the console tag should show you jQuery headers and responses to GET requests
- if that doesn't point the way, try console.log(Location) or similar in your code. You can also type commands in the console.

hth,


Mirza Rahman comments:

I was able to get it via Firebug. I just need to store it in a var

2012-07-02

Daniel Yoen answers:

Your code look like this :

function getData(key)
{
$.ajax({
type: "GET",
url: "http://searchlight.cluen.com/E5/Login.aspx)",
data: "URLKey=" + key,
success: function()
{
//if success
}
error: function()
{
//error handle
}
});
return false;
}


hope this help


Mirza Rahman comments:

I have tried this. But I still can't seem to store it in a variable

2012-07-02

idt answers:

Try the suggestions on this page:
[[LINK href="http://stackoverflow.com/questions/1557602/jquery-and-ajax-response-header"]]http://stackoverflow.com/questions/1557602/jquery-and-ajax-response-header[[/LINK]]

2012-07-03

Romel Apuya answers:

try this.. ur code should be like this..

$.ajax({
type: 'GET',
url:'http://searchlight.cluen.com/E5/Login.aspx?URLKey=uzr7ncj8)',
data: formData,
success: function(data, textStatus, XMLHttpRequest){
alert(XMLHttpRequest.getResponseHeader('some_header'));
}
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.getResponseHeader('some_header'));
}
});


Romel Apuya comments:

try this.. ur code should be like this..

$.ajax({
type: 'GET',
url:'http://searchlight.cluen.com/E5/Login.aspx?URLKey=uzr7ncj8)',
data: formData,
success: function(data, textStatus, XMLHttpRequest){
alert(XMLHttpRequest.getResponseHeader('some_header'));
}
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.getResponseHeader('some_header'));
}
});


Romel Apuya comments:

$.ajax({

type: 'GET',

url:'http://searchlight.cluen.com/E5/Login.aspx?URLKey=uzr7ncj8)',

data: URLKey,

success: function(data, textStatus, XMLHttpRequest){

alert(XMLHttpRequest.getResponseHeader('some_header'));

}

error: function (XMLHttpRequest, textStatus, errorThrown) {

alert(XMLHttpRequest.getResponseHeader('some_header'));

}

});

2012-07-03

Francisco Javier Carazo Gil answers:

Hi Mirza,

Try this, I have used it before:

var geturl;
geturl = $.ajax({
type: "GET",
url: 'http://....',
success: function () {
alert(geturl.getAllResponseHeaders());
}
});



Francisco Javier Carazo Gil comments:

Hi Mirza,

Try this, I have used it before:

var geturl;
geturl = $.ajax({
type: "GET",
url: 'http://....',
success: function () {
alert(geturl.getAllResponseHeaders());
}
});


2012-07-03

Rashad Aliyev answers:

$.ajax({
type: "GET",
url: 'http://searchlight.cluen.com/E5/Login.aspx?URLKey=uzr7ncj8)',
complete: function (XMLHttpRequest, textStatus) {
var headers = XMLHttpRequest.getAllResponseHeaders();
alert(headers);
}
});

2012-07-04

Lawrence Krubner answers:

Off topic: for some strange reason, there was spam posted to this site, earlier today, and yesterday. I have now made a few changes which should make spam a lot less likely.