Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.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-如何访问通过jquery ajax传递的对象_Php_Jquery_Ajax - Fatal编程技术网

php-如何访问通过jquery ajax传递的对象

php-如何访问通过jquery ajax传递的对象,php,jquery,ajax,Php,Jquery,Ajax,我有一个javascript对象,如下所示 var customerinfo = { customer_name : $('#customer_name').val(), customer_address: $('#customer_address').val(), customer_city : $('#customer_city').val(), customer_state : $('#cust

我有一个javascript对象,如下所示

var customerinfo = {
            customer_name : $('#customer_name').val(),
            customer_address: $('#customer_address').val(),
            customer_city : $('#customer_city').val(),
            customer_state : $('#customer_state').val(),
            customer_zip : $('#customer_zip').val(),
        };
$.ajax({
                    url: "../folder/file.php",
                    type: "POST", 
                    data: {
                     'customerinfo' : customerinfo,
                    },
                    success:function(){
                         window.location = "file.php";
                    }
            })
然后我尝试使用$.ajax将其传递给php,如下所示

var customerinfo = {
            customer_name : $('#customer_name').val(),
            customer_address: $('#customer_address').val(),
            customer_city : $('#customer_city').val(),
            customer_state : $('#customer_state').val(),
            customer_zip : $('#customer_zip').val(),
        };
$.ajax({
                    url: "../folder/file.php",
                    type: "POST", 
                    data: {
                     'customerinfo' : customerinfo,
                    },
                    success:function(){
                         window.location = "file.php";
                    }
            })
在php中,我尝试打印出对象

 $customerinfo = json_decode($_POST['customerinfo']);
 print_r($customerinfo);

我得到
未定义的索引customerinfo

在传递json.stringify之前,我还尝试在javascript中使用json.stringify,但得到了相同的错误

我发现了一个非常类似的帖子,比如 但是我也无法让代码正常工作。我认为ajax能够传递数据,只是我不知道如何在php端解码

我知道我可以从HTMLSubmit按钮发布它,但这是一个更大问题的简化测试,我想使用jquery传递包含许多对象的对象

如果javascript方面是正确的,那么问题是“如何在PHP中访问通过jquery ajax传递的对象。”


如果不是,问题将是
“如何将对象从javascript传递到php。”

据我所知,问题可能在数据中。 尝试使用静态数据过帐,这意味着替换

var customerinfo = {
        customer_name : $('#customer_name').val(),
        customer_address: $('#customer_address').val(),
        customer_city : $('#customer_city').val(),
        customer_state : $('#customer_state').val(),
        customer_zip : $('#customer_zip').val(),
    };


还可以尝试从浏览器控制台发送ajax,这样您就可以看到正在发布的数据

success:function(data){doSomethingWith(data);}
我不想从php获得响应。我真的想做一个重定向。所以我只是把它放在了成功中。