Javascript 在firefox中,ajax预飞行失败,选项响应为200

Javascript 在firefox中,ajax预飞行失败,选项响应为200,javascript,ajax,firefox,preflight,Javascript,Ajax,Firefox,Preflight,我有以下代码: Util.xmlGet = function(uriend, callback) { var xmlhttp; var uri; if (window.XMLHttpRequest) { // code for modern browsers xmlhttp=new XMLHttpRequest(); } else {// code for dinosaurs xmlhttp=new ActiveXObj

我有以下代码:

Util.xmlGet = function(uriend, callback) {
    var xmlhttp;
    var uri;
    if (window.XMLHttpRequest) {
        // code for modern browsers
        xmlhttp=new XMLHttpRequest();
    } else {// code for dinosaurs
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    if(document.URL.startsWith("file://")) {
        uri = "https://tomcat.realm:8443/worldmodel/worldmodel?";
    } else {
        uri = "/worldmodel/worldmodel?"
    }
    alert(uri+uriend);
    xmlhttp.onreadystatechange=function() {
        alert("readystate="+xmlhttp.readyState+", status="+xmlhttp.status);
        if (xmlhttp.readyState==4 && xmlhttp.status==0) {
            alert("preflight OK");
        }
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            alert("calling back");
            callback(xmlhttp.responseXML);
        }
    }
    xmlhttp.open("GET",uri+uriend,true);
    xmlhttp.setRequestHeader("Content-type","text/xml;charset=UTF-8");
    xmlhttp.send();     
   };
我在呼叫时看到以下警报:

  • URI
  • readystate=1,状态=0
  • readystate=2,状态=0
  • readystate=4,状态=0
  • 飞行前正常
浏览器发送选项请求,并收到“200”响应。更确切地说:

https://tomcat.realm:8443/worldmodel/worldmodel?type=thing
Request Method:
OPTIONS
Status Code:
HTTP/1.1 200 OK

Request Headers
14:35:30.000
User-Agent:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0
Origin:nullHost:tomcat.realm:8443
Connection:keep-alive
Access-Control-Request-Method:GET
Access-Control-Request-Headers:content-type
Accept-Language:hu,en-us;q=0.8,es;q=0.5,en;q=0.3
Accept-Encoding:gzip, deflateAccept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8


Response Headers  Δ5ms
Server:Apache-Coyote/1.1
Date:Thu, 06 Jun 2013 12:35:30 GMT
Content-Length:0
Allow:GET, HEAD, POST, TRACE, OPTIONS
永远不会发送GET请求,onreadystatechange不再发送状态

这是从Firefox21.0 Mozilla Firefox for Ubuntu Canonical-1.0(这是help/about Firefox报告的内容)在本地文件系统中的html文件上完成的

这里有什么问题


firefox不阻止本地文件系统中的文件向任何地方发出xhr请求吗?首先,由于安全原因,它不能引用同一个域(本地文件系统)。第二个原因是由于同源策略,它无法访问其他域


firefox不阻止本地文件系统中的文件向任何地方发出xhr请求吗?首先,由于安全原因,它不能引用同一个域(本地文件系统)。第二个原因是由于同源策略,它无法访问其他域。当您安装forcecors插件并使用view=>toolbars=>addon bar激活它时会发生什么。然后单击右下角的“cors”文本。现在,您可以从任何地方发出xhr请求。有关更多信息,请查看wikipedia的同源策略。请尝试,谢谢提示。cors添加的标题显示在网络控制台看到的选项响应中,但所有其他症状都是相同的。我可以从本地文件打开一个xhr连接,并激活forecors插件。使用jquery(所有本地)打开一个文件,并在控制台中粘贴以下代码:
$.ajax(“http://www.google.com.hk");请求完成,我可以在控制台中看到响应。当forcecors未激活时,请求变为红色,我看不到响应。如果您的web服务器发送了正确的cors响应头,那么它在没有forcecors的情况下应该可以工作。使用dojo尝试过: