Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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不执行函数?使用HREF_Php_Html_Ajax - Fatal编程技术网

Php 为什么AJAX不执行函数?使用HREF

Php 为什么AJAX不执行函数?使用HREF,php,html,ajax,Php,Html,Ajax,index.php <a href="#" onclick="doSomething();"></a> function doSomething() { $.get("server.php?test"); return false; } </script> 函数doSomething(){ $.get(“server.php?test”); 返回false; } 这是server.php应该给出的响应 if(isset($_GET[

index.php

<a href="#" onclick="doSomething();"></a>
function doSomething() {
    $.get("server.php?test");
    return false;
}
</script>   

函数doSomething(){
$.get(“server.php?test”);
返回false;
}
这是server.php应该给出的响应

if(isset($_GET['test'])){
echo '<script type="text/javascript">alert("hello!");</script>';
}   
if(isset($\u GET['test'])){
回音“警报(“你好!”);
}   
有几件事:

  • 请求参数仍然需要
    x=y
    供PHP查看

     #                     ↓↓
     $.get("server.php?test=1");
    
  • 对于测试,避免,但启用

    isset
    用于在您验证一切正常工作后抑制警告。不要习惯性地使用它

  • 使用浏览器开发工具F12/网络选项卡检查向脚本发送了哪些GET参数。在你的问题中包括这一点

  • 回显的
    与您当前使用的
    $没有任何关系。get(…)。相反,只需输出文本响应进行测试,并且:

    // alert out the response
    $.get("srv?test=1", function(data, s){
        alert(data);
    });
    

新帐户?这仍然没有比以前更多的尝试。有URL和HTTP请求调试吗?感谢您花宝贵的时间回答这个问题。
// alert out the response
$.get("srv?test=1", function(data, s){
    alert(data);
});