javascript - Redirect after POST using the Location header with jQuery -
i want redirect target using location header jquery 1.7.
my code looks
$('#creationlink').click(function(){ $.ajax({ type: 'post', url: '/', success: function(data, textstatus, xhr) { window.location = xhr.getresponseheader("location"); } }) }); ... not work. xhr.getresponseheader("location") null.
http headers:
post / http/1.1 host: localhost:9000 x-requested-with: xmlhttprequest content-length: 0 http/1.1 302 found content-type: text/plain; charset=utf-8 location: http://localhost:9000/virdd0pdwp4/bearbeiten content-length: 0 how can redirect using location header?
afaik, browsers supposed to, during xhr, transparently follow redirect in response header. is, xhr @ response, see location header, , proceed magically run second request uri. when has result of that give @ all, , gives result of second request.
see this stackoverflow answer!
so, if need redirect feature, you'll have make thing request return target uri in other way, e.g. json response.
see this stackoverflow solution!
ps. reference: http://www.w3.org/tr/xmlhttprequest/#infrastructure-for-the-send-method
Comments
Post a Comment