i'm using ajax form jquery plugin to submit a form (in a dialog) via ajax.
this works fine and then i get the html response back from the server. the response es from a standard redirect-after-post php page which i cannot modify.
is there a way to obtain the url of this redirect (the final GET location) using jquery (inside the ajax callback) ?
$j('span.sfAutoplete a').click(function(e){
var url = this.href;
var $dialog = $j('<div id="ajaxDialog"></div>').appendTo('body')
.load(
url,
'sfAutoplete=true',
function (responseText, textStatus, XMLHttpRequest) {
$dialog.dialog({ autoOpen: true });
//
// Ajax submit
//
$j('#ajaxDialog form').submit(function() {
function showResponse(responseText, statusText) {
// how to get the redirect url ?
}
$j(this).ajaxSubmit({
success: showResponse
});
return false;
});
}
);
return false;
});
i'm using ajax form jquery plugin to submit a form (in a dialog) via ajax.
this works fine and then i get the html response back from the server. the response es from a standard redirect-after-post php page which i cannot modify.
is there a way to obtain the url of this redirect (the final GET location) using jquery (inside the ajax callback) ?
$j('span.sfAutoplete a').click(function(e){
var url = this.href;
var $dialog = $j('<div id="ajaxDialog"></div>').appendTo('body')
.load(
url,
'sfAutoplete=true',
function (responseText, textStatus, XMLHttpRequest) {
$dialog.dialog({ autoOpen: true });
//
// Ajax submit
//
$j('#ajaxDialog form').submit(function() {
function showResponse(responseText, statusText) {
// how to get the redirect url ?
}
$j(this).ajaxSubmit({
success: showResponse
});
return false;
});
}
);
return false;
});
Share
Improve this question
asked Nov 3, 2009 at 9:25
gpilotinogpilotino
13.3k9 gold badges50 silver badges62 bronze badges
1 Answer
Reset to default 3I haven't used the plug-in you are using, but if you use the jQuery Ajax mand, you receive the XMLHttpRequest object as a parameter to the plete
event. You can then get the post URL from the HTTP header that returns. Try the following:
$.ajax({
url:'your.url',
data:'your data',
plete: function(xhr,textstatus) {
// xhr.responseText contains the response from the server
var allheaders = xhr.getAllResponseHeaders();
// this will get all headers as a string - if you want them as an object...
var eachheader = allheaders.split('\n');
var headers = {};
for(i = 0; i < eachheader.length; i++) {
if ($.trim(eachheader[i]) !== '') {
headersplit = eachheader[i].split(':');
headers[headersplit[0]]=$.trim(headersplit[1]);
}
}
}
});
This code was copied from this thread.