【问题标题】:XmlHttp Request status 0, localhost issues (javascript, ajax, php) helpXmlHttpRequest 状态 0,本地主机问题(javascript、ajax、php)帮助
【发布时间】:2011-03-06 11:06:55
【问题描述】:

我正在使用 xampp 来测试我的代码。我正在使用 Dreamweaver 实时取景。在实时视图中,返回 200 的 xmlhttp.status 代码和回显输出。但是当我尝试在 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)。

我的代码如下,该行中的相对 url 在 DW 实时视图中有效,但在使用 FF/IE 浏览器独立访问时无效

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

我应该用什么替换 url 才能正常工作?

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

【问题讨论】:

    标签: ajax xmlhttprequest http-status-codes


    【解决方案1】:

    如果您将 IE 或 FF 指向磁盘上的文件,并且您的文件使用 ajax 处理 http://localhost/app/blah,则您违反了同源策略。

    您可以通过 about:config 在 Firefox 中通过切换来更改此设置:

    security.fileuri.strict_origin_policy

    还有用于更改浏览器安全设置的 java 脚本解决方案。

    【讨论】:

    • 感谢您的回复,但我仍然不确定如何让它工作。
    猜你喜欢
    • 2013-04-22
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    相关资源
    最近更新 更多