简体   繁体   English

jQuery Ajax发布到php,但变量中没有值

[英]Jquery ajax post to php but is saying no value in variable

I am working on an instant search thing and when I submit the form search-form it is going to make an ajax post to PHP. 我正在研究即时搜索,当我提交表单search-form时,它将向PHP发送ajax帖子。 It sends and everything but then the PHP page says that the variable has no value but the data is clearly being posted. 它发送了所有内容,但是随后PHP页面说该变量没有值,但是数据显然已发布。

        $('#search-form').submit(function(event) {
            event.preventDefault();
            $.ajax({
                type: "POST",
                url: "Search.php",
                cache: false,
                data: $("#search-form").serialize(),
                success: function(data) {
                    alert($("#search-form").serialize());
                    $("#searched").fadeIn("fast");
                    $("#results").empty();
                    $("#results").append(data);
                }
            });
            return false;
        });

Make sure you have a console opened up in your browser, Firefox: bugzilla, Chrome and IE have a built-in. 确保在浏览器Firefox中打开了控制台:bugzilla,Chrome和IE具有内置功能。 It shows you what is happening in asynchronous requests. 它显示了异步请求中发生的事情。

in your php file at the top do this: 在顶部的php文件中执行以下操作:

var_dump($_POST);

//OR DO THIS:
// print_r($_POST);

Then look at your browser console to see what the response is. 然后查看您的浏览器控制台以查看响应是什么。 It should spit out an array. 它应该吐出一个数组。 and you can see what the name of your data is. 然后您可以看到数据的名称。 This is the quickest way to debug any ajax request. 这是调试任何ajax请求的最快方法。

Also, don't forget that you serialized the data with .serialize(); 另外,不要忘记使用.serialize()序列化了数据;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM