Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
一个简单的错误。无法加载XMLHttpRequesthttp://localhost/mpl/getPage.php. 访问控制不允许原点为null允许原点_Php_Javascript_Ajax_Cordova - Fatal编程技术网

一个简单的错误。无法加载XMLHttpRequesthttp://localhost/mpl/getPage.php. 访问控制不允许原点为null允许原点

一个简单的错误。无法加载XMLHttpRequesthttp://localhost/mpl/getPage.php. 访问控制不允许原点为null允许原点,php,javascript,ajax,cordova,Php,Javascript,Ajax,Cordova,可能重复: 我是JavaScript Phonegap和AJAX的新手。我正在尝试编写一个简单的Phonegap应用程序,该应用程序将从服务器请求消息,但该应用程序没有响应。当我在chrome浏览器上以文件形式运行我的脚本时,因为我知道Phonegap是如何工作的,它显示无法加载foll-XMLHttpRequesthttp://localhost/mpl/getPage.php. 访问控制允许原点不允许原点为null 我怎样才能解决这个问题?我的代码在下面 <html> <

可能重复:


我是JavaScript Phonegap和AJAX的新手。我正在尝试编写一个简单的Phonegap应用程序,该应用程序将从服务器请求消息,但该应用程序没有响应。当我在chrome浏览器上以文件形式运行我的脚本时,因为我知道Phonegap是如何工作的,它显示无法加载foll-XMLHttpRequesthttp://localhost/mpl/getPage.php. 访问控制允许原点不允许原点为null

我怎样才能解决这个问题?我的代码在下面

<html>
<head>
<script type="text/javascript">
function getMessage()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("serverReply").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","http://localhost/mpl/getPage.php",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="serverReply" onclick="getMessage();"><b>Get message</b></div>

</body>
</html>
请帮帮我。谢谢。

使用下面的代码

<div id="serverReply"><b><a href="#"  onclick="getMessage();">Get message</a></b></div>
而不是

<div id="serverReply" onclick="getMessage();"><b>Get message</b></div>
或者试试这个


当我在chrome浏览器上以文件的形式运行脚本时,[…]在file://协议上不允许XMLHttpRequest
<div id="serverReply" onclick="getMessage();"><b>Get message</b></div>
<html>
<head>
<script type="text/javascript">
function getMessage()
{
  if (window.XMLHttpRequest)
  {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      
  }else
  {
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
    
    xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        alert(xmlhttp.responseText);
        document.getElementById("serverReply").innerHTML=xmlhttp.responseText;
     
    }
  }
    xmlhttp.open("GET","http://localhost/mpl/getPage.php",true);
    xmlhttp.send();
}
</script>
</head>
<body>

<div id="serverReply"><b><a href="#"  onclick="getMessage();">Get message</a></b></div>

</body>
</html>