Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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
PHP、AJAX和HTML,从未调用过函数_Php_Javascript - Fatal编程技术网

PHP、AJAX和HTML,从未调用过函数

PHP、AJAX和HTML,从未调用过函数,php,javascript,Php,Javascript,可能重复: 我有一个这样的按钮: <form method="post" id="submit" action="script/gen.php"> <input type="button" onClick="getKey()" value="Generate key"/> <script type="text/javascript"> function getKey() { if (window.XMLHtt

可能重复:

我有一个这样的按钮:

<form method="post" id="submit" action="script/gen.php">
    <input type="button" onClick="getKey()" value="Generate key"/>
<script type="text/javascript">
        function getKey() {
            if (window.XMLHttpRequest) {
                xmlhttp=new XMLHttpRequest();

        }
        else {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.getElementById("innhold").innerHTML=xmlhttp.responseText;
        }
    }
        xmlhttp.open("GET","script/gen.php?returnKey",true);
        xmlhttp.send();
    }
</script>
此函数从未被调用过,即使我在调用函数之前添加了一个
echo

有人能看出问题出在哪里吗

编辑

这是控制台从chrome告诉我的:

XMLHttpRequest cannot load file:///C:/wamp/www/Webpanel/script/gen.php?returnKey. Cross    origin requests are only supported for HTTP.
Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101 index.html:37
getKey index.html:3
编辑2

天哪,摩西,我知道了。必须在我的浏览器中键入localhost/Webpanel。这是漫长的一天,所以我不太清楚。

问题解决了:


我试图在本地打开我的
index.html
,这是正确的方法,ofc。在浏览器中键入
localhost
。您必须运行
WAMP

在Chrome中打开此程序,打开控制台(F12),然后检查网络面板以查看请求是否通过。如果是这样,那就是服务器端的问题。我不确定
$\u GET[“returnKey”]
是否会被视为
NULL
。在
'script/gen.php?returnKey'之后添加
=
。并检查状态是否为200和状态是否为4。您可以在PHP中运行
echo(json_encode($\u GET))
,以确保存在returnKey属性?是否通过将
index.html
拖放到浏览器窗口来运行它?
XMLHttpRequest cannot load file:///C:/wamp/www/Webpanel/script/gen.php?returnKey. Cross    origin requests are only supported for HTTP.
Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101 index.html:37
getKey index.html:3