Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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/ajax/6.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
尝试通过stringify将数组传递到php时遇到问题_Php_Ajax - Fatal编程技术网

尝试通过stringify将数组传递到php时遇到问题

尝试通过stringify将数组传递到php时遇到问题,php,ajax,Php,Ajax,我不明白为什么这不起作用,请帮帮我!!我刚收到消息“decoded=” 正如@Reanimation所建议的,您需要发送保存JSON数据的参数。我建议您以更JavaScriptish的方式进行操作,如下所示: $.ajax({ type: 'post', cache: false, url: 'parser.php', data: {'myJson': mydata}, datatype: 'json', success: function(ms

我不明白为什么这不起作用,请帮帮我!!我刚收到消息“decoded=”



正如
@Reanimation
所建议的,您需要发送保存JSON数据的参数。我建议您以更JavaScriptish的方式进行操作,如下所示:

$.ajax({
    type: 'post',
    cache: false,
    url: 'parser.php',
    data: {'myJson': mydata},
    datatype: 'json',
    success: function(msg){
            $("#formstatus").ajaxComplete(function(){$(this).html(msg)});
    }        
});

另一件事是,
$decoded
实际上将保留一个数组,只要原始的
数组\u str\u idnum
是数组,那么执行
echo$decoded
将输出
数组()
。另请注意,要使用的第二个参数是将对象作为关联数组返回。

您是否已转储$\u POST的内容以查看其中包含的内容?请尝试使用
json\u last\u error打印最后一个错误(如果有)
我对jQuery不太熟悉,但数据不必包含查询字符串吗?您可以尝试使用“data:'myJson='+mydata”而不仅仅是“data:mydata”。不管是哪种方式,我都没有看到任何myJson数据被设置。谢谢大家,我实现了这一点,并做了一个var转储字符串(33)”[[\“1316333978281\”],[\“moved\”]]“谢谢大家,我实现了这一点,并在$u POST变量上做了一个var转储,该变量返回:“string(33)”[\“1316333978281\”],[\“moved\”]“这是括号中的正确数据,但它似乎不想把它解码成一个数组。我会继续努力!事实证明,我不需要首先对数组进行字符串化,它可以按原样传递。再次感谢那些帮助我的人。
<?php

// decode JSON string to PHP object
$decoded = json_decode($_POST['myJson'],true);

echo "decoded =";
echo $decoded;

?>
$.ajax({
    type: 'post',
    cache: false,
    url: 'parser.php',
    data: {'myJson': mydata},
    datatype: 'json',
    success: function(msg){
            $("#formstatus").ajaxComplete(function(){$(this).html(msg)});
    }        
});