实现CORS时未获得响应 [英] No response obtained while implementing CORS
问题描述
我在我的网站上使用CORS进行跨网域通话。虽然,响应标题如图所示,似乎对我很好,但我没有收到任何响应。它仍然为空白或返回与响应。任何人都可以预测我的方法中的错误,看到附加的图片?
I am using CORS for cross-domain talk on my website. Although, the response header as shown in the pic, seems fine to me, yet, I am not receiving any response. Its still blank or returns with response. Can anyone predict the error in my approach, seeing the attached image ?
在服务器端,我使用此片段
At server side, I am using this snippet
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true ");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
在客户端,我有: -
While at the client side , I have :-
function getXMLHTTPRequest() {
try {
req = new XMLHttpRequest();
} catch(err1) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (err2) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (err3) {
req = false;
}
}
}
return req;
}
var http899 = getXMLHTTPRequest();
http899.open("GET", modurl, true);
http899.setRequestHeader('Content-Type', 'text/html');
http899.onreadystatechange = useHttpResponse899;
http899.send(null);
推荐答案
不一定是一个完整的答案,但我认为一些浏览器不接受多Access-Control-Allow-Origin头中的条目。我不知道Firefox是不是其中之一。
Not necessarily a complete answer, but I think some browsers don't accept multiple entries in the "Access-Control-Allow-Origin" header. I don't know if Firefox is one of them.
也许尝试将请求的Origin标头复制到响应的Access-Control-Allow-Origin在您要接受的起源列表中?
Maybe try copying the request's "Origin" header into the response's "Access-Control-Allow-Origin" if it's in the list of origins you want to accept?
这篇关于实现CORS时未获得响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!