XmlHttp 请求状态 0,本地主机问题(javascript、ajax、php)帮助

发布于 2024-09-11 15:45:35 字数 1393 浏览 3 评论 0原文

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

基本上,我有一个 html 文件,它调用 javascript 函数“result()”,“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

I am using xampp to test my codes. I am using dreamweaver live view. In live view, and return a xmlhttp.status code of 200 and echo outputs. But when I try to view it in IE or FF, the status code is 0, and no output. I read that this seems to be a problem with the URL (absolute/relative??), I tried multiple URL formats, but can't seem to get it to work.

Basically, I have an html file that calls the javascript function "result()", the "result" functions calls to execute a test3.php file.

The location of file to be called is C://xampp/htdocs/test/ha/test3.php

I tested file:///C://xampp/htdocs/test/ha/test3.php or C://xampp/htdocs/test/ha/test3.php or file:///xampp/htdocs/test/ha/test3.phpPlease suggest a URL format (the complete url).

my code is below, as is, the relative url in the line works in DW live view, but not when independently accessed with FF/IE browsers

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

What should I replace the url with for it to work?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-09-18 15:45:35

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

您可以在 Firefox 中通过 about:config 通过切换

security.fileuri.strict_origin_policy

来更改此设置,还有一些 Java 脚本解决方案可以更改浏览器的安全设置。

if you are pointing IE or FF at a file on your disk, and your file uses ajax for an http://localhost/app/blah you are violating the same origin policy.

You can change this in firefox by about:config by toggling:

security.fileuri.strict_origin_policy

there are also java script solutions for this that change the browsers security settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文