【发布时间】:2013-08-14 21:57:08
【问题描述】:
我正在处理 javascript 跨域 ajax 请求。我的代码在 chrome 和其他设备上运行良好,例如 android 浏览器和使用 phonegap 的 android 本机应用程序。 但我遇到了 Firefox 的问题..
Firefox 不支持我的 PUT 和 DELETE 请求。 Firefox 有什么解决方案可以向我的服务器发出 put 和 delete 请求。
firefox 确实支持我的帖子和获取请求。两者都要求工作正常。
这是我的工作代码。
var XMLHttpFactories = [
function () {
return new XMLHttpRequest()
},
function () {
return new ActiveXObject("Msxml2.XMLHTTP")
},
function () {
return new ActiveXObject("Msxml3.XMLHTTP")
},
function () {
return new ActiveXObject("Microsoft.XMLHTTP")
}
];
function createXMLHTTPObject() {
var xmlhttp = false;
for (var i=0;i<XMLHttpFactories.length;i++) {
try {
xmlhttp = XMLHttpFactories[i]();
}
catch (e) {
continue;
}
break;
}
return xmlhttp;
}
用于发送 Put 请求..
var xhr = createXMLHTTPObject();
xhr.open("PUT", url,true);
xhr.onreadystatechange=function()
{
if (xhr.readyState==4)
{
if(xhr.status==200){
request.success(xhr.responseText);
}else if(xhr.status!=200){
request.error(xhr.responseText)
}
}
}
xhr.send(body);
【问题讨论】:
-
您应该发布执行
PUT和DELETE请求的代码,而不是发布工厂代码 -
有任何来自 FireFox 的错误消息吗?
-
在 Firefox 中没有发生任何事情......没有收到任何错误......
-
我觉得没问题:jsfiddle.net/C275E/1
标签: javascript ajax html xmlhttprequest