【发布时间】:2011-12-30 12:42:31
【问题描述】:
我有这个代码:
net.requestXHR = function() {
this.xhr = null;
if(window.XMLHttpRequest === undefined) {
window.XMLHttpRequest = function() {
try {
// Use the latest version of the activex object if available
this.xhr = new ActiveXObject("Msxml2.XMLHTTP.6.0");
}
catch(e1) {
try {
// Otherwise fall back on an older version
this.xhr = new ActiveXObject("Mxsml2.XMLHTTP.3.0");
}
catch(e2) {
//Otherwise, throw an error
this.xhr = new Error("Ajax not supported in your browser");
}
}
};
}
else
this.xhr = new XMLHttpRequest();
}
net.requestXHR.prototype.post = function(url, data) {
if(this.xhr != null) {
this.xhr.open("POST", url);
this.xhr.setRequestHeader("Content-Type", "application/json");
this.xhr.send(data);
}
}
var rs = new net.requestSpeech();
console.log(JSON.stringify(interaction));
rs.post("http://localhost:8111", JSON.stringify(interaction));
当发送执行时,我有这个日志:
OPTIONS http://localhost:8111/ [HTTP/1.1 405 Method Not Allowed 74ms]
在 localhost:8111 我有一个接受 post 的 reslet serverResource,这是同源策略的问题吗?我已经修改了restlet以放置allow-origin标头,并使用另一个GET http请求(在jquery中)对其进行测试并且工作正常。我解决了同源问题,因为我使用的是 html5 浏览器,而我的服务器将标头放入响应中,那么为什么发送显示此错误?为什么将 POST 更改为 OPTION? 谢谢!
可能重复?:我认为没有,但确实如此,问题在于 两个问题都一样,但我的问题是 浏览器有问题,另一个首先指向 jQuery。根据经验,时间不算重复, 答案是不同的,但确实这两个问题都是互补的 彼此。
【问题讨论】: