Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.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/1/php/259.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
通过ajaxpost发送javascript多维数组_Javascript_Php_Arrays_Ajax_Send - Fatal编程技术网

通过ajaxpost发送javascript多维数组

通过ajaxpost发送javascript多维数组,javascript,php,arrays,ajax,send,Javascript,Php,Arrays,Ajax,Send,我有一个多维数组,如下所示 var myarray = new Array(); myarray["firstkey"] = new Array(); myarray["firstkey"]["secondkey"] = new Array(); myarray["firstkey"]["secondkey"]["0"] = new Array(); myarray["firstkey"]["secondkey"]["0"]["a"] = 100; myarray["firstkey"]["se

我有一个多维数组,如下所示

var myarray = new Array();
myarray["firstkey"] = new Array();
myarray["firstkey"]["secondkey"] = new Array();
myarray["firstkey"]["secondkey"]["0"] = new Array();
myarray["firstkey"]["secondkey"]["0"]["a"] = 100;
myarray["firstkey"]["secondkey"]["0"]["b"] = 1200;
myarray["firstkey"]["secondkey"]["0"]["c"] = 32000;
myarray["firstkey"]["secondkey"]["0"]["d"] = 23001;
myarray["firstkey"]["secondkey"]["0"]["e"] = "text";
myarray["firstkey"]["secondkey"]["0"]["f"] = "text";
myarray["firstkey"]["secondkey"]["0"]["g"] = "text";
myarray["firstkey"]["secondkey"]["0"]["h"] = "";
myarray["firstkey"]["secondkey"]["0"]["i"] = 0;
myarray["firstkey"]["secondkey"]["0"]["aa"] = new Array();
myarray["firstkey"]["secondkey"]["0"]["bb"]["bbb"] = 16;
myarray["firstkey"]["secondkey"]["0"]["cc"]["ccc"] = "text";
myarray["firstkey"]["secondkey"]["0"]["dd"]["ddd"] = new Array();
myarray["firstkey"]["secondkey"]["0"]["ee"]["eee"]["0"] = "text";
myarray["firstkey"]["secondkey"]["0"]["ff"]["fff"]["1"] = "text";`

我想从PHP中得到它,但我找不到解决方案。谁能告诉我解决办法吗。非常感谢您的回复。

也许您可以尝试发送JSON

您应该使用以下内容从PHP中阅读:

$json = file_get_contents("php://input");
你可以做AJAX

JavaScript:

var array = JSON.stringify(myarray);
$.ajax({
    url: "/myphp/file.php",
    data: {array: array},
    dataType: "json",
    success: function(data){
        alert(data["return"]);
    }
});
$array = json_decode($_POST["array"]);
$savedVal = $array["firstkey"]["secondkey"]["0"]["a"];
echo json_encode(array("return" => $savedVal));
PHP:

var array = JSON.stringify(myarray);
$.ajax({
    url: "/myphp/file.php",
    data: {array: array},
    dataType: "json",
    success: function(data){
        alert(data["return"]);
    }
});
$array = json_decode($_POST["array"]);
$savedVal = $array["firstkey"]["secondkey"]["0"]["a"];
echo json_encode(array("return" => $savedVal));

“我想从php获取它”是什么意思?当我通过ajax发送它时,它向我显示[],在php$\u帖子中显示Array()True。当您只将带有POST的JSON发送到PHP时,$\u POST为空。然后,您将收到带有
$json=file\u get\u内容(“php://input");。然后你可以用
json\u decode()
解码它。首先感谢你的回答,但是当我从你的方式发送它时,post中的数组显示我是空白的,我无法在php获取数据,直到数据应该被post,对于多维数组,哪个键类似于字符串,它总是给我空白。你明白我的问题了吗?JSON stringify例程可能会忽略字符串键属性,而只序列化数字索引属性。你自己尝试过吗?