jQuery的AJAX - 做浏览器请求的重定向头新位置

问题描述:

可以jQuery的阿贾克斯取得的浏览器发送请求由服务器重定向头一个新的位置?

Can jQuery ajax made browser request a new location in redirect header send by server?

您应该解析code和使用JavaScript来设置document.location

You should parse the code and use Javascript to set the document.location

$.get('page.php', { GETvar : 'redirectUrl' }, function(data, textString){  
 if (textString == "succes") { //Succes!
  document.location = data;
 }
 else{ // failure }
});

如果你的PHP脚本返回一个有效的URL,这将设置位置的URL。

If you PHP script returns a valid url this will set the location to that url.

修改
你也可以使用隐藏的iFrame是这样的:
HTML:

EDIT
You could also use a hidden iFrame like this:
html:


     <iframe src="blank.html" name='hiddenframe' id='hiddenframe' onload='readyLoad()'>

然后用一些JavaScript这样

And then use some Javascript like this

var first = true;
function setRedirect (url) {
 hiddenframe.location = url;
}
function readyLoad() {
 if( first == true ) { first = false; return false; }
 else {
 alert( 'ready loading, was redireced too:' + myFrame.location.href );
 //Use new location code
}
}

您应该包装这些功能到使用jQuerys可爱的小事件处理程序建立在该功能(他们都是伟大)。

You should wrap these function into nice little event handlers using jQuerys build in functions for that (they are great).