XmlHttp请求状态0,localhost问题(javascript,ajax,php)帮助

时间:2010-07-26 19:59:11

标签: ajax xmlhttprequest http-status-codes

我正在使用xampp来测试我的代码。我正在使用Dreamweaver实时视图。在实时视图中,返回xmlhttp.status代码200和echo输出。但是当我尝试在IE或FF中查看它时,状态代码为0,没有输出。我读到这似乎是URL的问题(绝对/相对??),我尝试了多种URL格式,但似乎无法让它工作。

基本上,我有一个调用javascript函数“result()”的html文件,“result”函数调用执行test3.php文件。

要调用的文件的位置是C://xampp/htdocs/test/ha/test3.php

我测试了file:/// C://xampp/htdocs/test/ha/test3.php或C://xampp/htdocs/test/ha/test3.php或file:/// xampp / htdocs /test/ha/test3.php请建议一个URL格式(完整的URL)。

我的代码如下所示,该行中的相对网址在DW实时视图中工作,但在使用FF / IE浏览器独立访问时则不行

xmlhttp.open("GET","../ha/test3.php",true);

我应该更换网址以使其工作?

TIA

function Result() 
{


xmlhttp = ajaxFunction();
//document.getElementById("results").innerHTML += " ajax function got executed";

xmlhttp.onreadystatechange=function()
  {

  document.getElementById("results").innerHTML += xmlhttp.readyState; //readystate check/debug
  document.getElementById("results").innerHTML += xmlhttp.status; //status check/debug

   if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      document.getElementById("results").innerHTML += "onreadystate";  //readystate check/debug

      document.getElementById("results").innerHTML += xmlhttp.responseText;



    }

    }
  }//onreadystate bracket



xmlhttp.open("GET","../ha/test3.php",true);

xmlhttp.send();

} //result function bracket

1 个答案:

答案 0 :(得分:0)

如果您将IE或FF指向磁盘上的文件,并且您的文件使用ajax作为http://localhost/app/blah,则违反了相同的原始政策。

您可以在firefox中通过about:config by toggling:

更改此设置

security.fileuri.strict_origin_policy

还有一些java脚本解决方案可以改变浏览器的安全设置。

相关问题