I have an ajax call that is working fine on Chrome, FF and Safari but always fail on IE ("success but no data"). I've checked server logs and the right response always triggers but still IE shows empty response and doesn't catch the right 302 http status code. I've tried many combinations and found that when using contentType: "text/html; charset=utf-8" IE does get the response but the problem is that $_POST array is empty since sending POST should be contentType: "application/x-www-form-urlencoded; charset=utf-8"
我有一个在Chrome,FF和Safari上工作正常的ajax调用但在IE上总是失败(“成功但没有数据”)。我检查了服务器日志,并且正确的响应总是触发,但IE仍显示空响应,并且没有捕获正确的302 http状态代码。我尝试了很多组合,发现使用contentType时:“text / html; charset = utf-8”IE确实得到了响应,但问题是$ _POST数组是空的,因为发送POST应该是contentType:“application / x -www-form-urlencoded; charset = utf-8“
This is my javascript:
这是我的javascript:
function someFunc() {
$.ajax({
cache: false,
async: false,
type: 'POST',
dataType: 'html',
contentType: "application/x-www-form-urlencoded; charset=utf-8",
//contentType: "text/html; charset=utf-8",
url: myProtocol + myHost + "/mypage.php",
data: {action: "someAction"},
success: function( data ) {
if (data == ""){
alert("success but no data");
return;
}
// do something...
return;
},
error: function( data ) {
if (data.status == "302"){
// do something...
return;
} else {
// do something...
return;
}
}
});
return;
}
this is my PHP response (mypage.php):
这是我的PHP响应(mypage.php):
$loginUrl = "someUrl";
header("HTTP/1.1 302 Found");
header("Content-Type: text/html; charset=utf-8");
Header("Content-Length: " . mb_strlen($loginUrl, "8bit"));
header("Connection: close", true);
echo $loginUrl;
Only on IE 7-9 I end up with "success but no data" on other browsers works perfect. any idea? somebody?
仅在IE 7-9上我最终获得“成功但没有数据”在其他浏览器上工作完美。任何想法?有人?
Thanks!
2 个解决方案
#1
0
Do you send Location header?
你发送位置标题?
header("Location:", $loginUrl);
Look at 14.30 Location: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
请看14.30位置:http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
#2
0
The problem was with the fact that IE is trying to follow the redirect location which was not what I wanted to do in my JS. the workaround I did was to change the response to 200 OK and make the JS detect if a URL is in response then do something with it:
问题在于IE正在尝试遵循重定向位置,这不是我想在我的JS中做的。我做的解决方法是将响应更改为200 OK并让JS检测URL是否响应,然后对其执行某些操作:
success: function( data ) {
if (data.match('http://') || data.match('https://')){
window.parent.location = data;
return;
} else {
var url = (window.location != window.parent.location) ? document.referrer: document.location;
window.parent.location = url;
return;
}
}
#1
0
Do you send Location header?
你发送位置标题?
header("Location:", $loginUrl);
Look at 14.30 Location: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
请看14.30位置:http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
#2
0
The problem was with the fact that IE is trying to follow the redirect location which was not what I wanted to do in my JS. the workaround I did was to change the response to 200 OK and make the JS detect if a URL is in response then do something with it:
问题在于IE正在尝试遵循重定向位置,这不是我想在我的JS中做的。我做的解决方法是将响应更改为200 OK并让JS检测URL是否响应,然后对其执行某些操作:
success: function( data ) {
if (data.match('http://') || data.match('https://')){
window.parent.location = data;
return;
} else {
var url = (window.location != window.parent.location) ? document.referrer: document.location;
window.parent.location = url;
return;
}
}