Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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 $.post('链接',…)不起作用_Php_Jquery_Post - Fatal编程技术网

Php $.post('链接',…)不起作用

Php $.post('链接',…)不起作用,php,jquery,post,Php,Jquery,Post,这是我的密码 <input type="text" id="name" class="name"> <button id= "det_submit" onclick="submit_det()"> Submit </button> <script> function submit_det() { if(document.getElementById("name").value != "") { $.pos

这是我的密码

<input type="text" id="name" class="name"> 
<button id= "det_submit" onclick="submit_det()"> Submit </button>   
<script>
function submit_det() {    
    if(document.getElementById("name").value != "") {   
       $.post(
             'subscribe.php',{email : document.getElementById("name").value},
              function(data){
                  alert(data);
              });
    } else {
         alert("empty");
     }
   } 
</script>

变量电子邮件未发送到subscribe.php页面…非常感谢您的帮助…谢谢您

尝试这种方式,您的代码很好,但您没有包含JQUERY API,我添加了CDN链接,您可以在下载后添加本地版本

<input type="text" id="name" class="name">
<button id= "det_submit" onclick="submit_det()"> Submit </button>
<script src="https://code.jquery.com/jquery-1.11.2.js"></script>
<script>
    function submit_det() {
        if(document.getElementById("name").value != "") {
            $.post(
                'subscribe.php',{email : document.getElementById("name").value},
                function(data){
                    alert(data);
                });
        } else {
            alert("empty");
        }
    }
</script>

脚本被调用了吗?是的。如果输入字段为空,它就工作了。您使用的jquery版本是什么?似乎工作得很好?如何在服务器端获取数据?按钮是元素的后代吗?您发布的HTML标记不建议,但。。。无论如何,你们必须提供有问题的最低限度的样本来复制这个问题