是我得到的错误是这样的,如果我使用的dataType:“JSON”:无法显示JSON对象
Uncaught TypeError: Cannot read property 'length' of undefined
如果我使用dataType:'html'
话,我可以看到数组传递形式的PHP页面在控制台像这样:
[{
"type": ["4 wheeler", "flying car", "test type"],
"maker": ["Honda", "Audi", "test car"],
"rate": [
["0", "78"],
["0", "56"],
["0", "34"],
["2", "78"],
["2", "56"],
["2", "34"],
["1", "89"],
["1", "7"],
["1", "56"]
]
}]
在我的php页面,这是我如何传递多维数组。
$json=array();
array_push($json,array("type"=>$carType,"maker"=>$carMaker,"rate"=>$selectRate));
echo json_encode($json);
这是我的错吗? AM我没有从这个页面传入JSON对象?如何在成功函数中通过jquery访问每个数组中的每个元素?阿贾克斯
$("#submit").on("click",function()
{
$("#set_setting").submit(function(){
data = $(this).serialize()
$.ajax({
type: "POST",
dataType: "html",
url: "submit_setting.php", //Relative or absolute path to response.php file
data: data,
success: function(data) {
//alert(JSON.stringify(data));
//data=JSON.stringify(data);
console.log(data);
//hide the form
$("#set_setting").slideUp("slow");
//show the result
$.each(data.type, function(index, value){
console.log(value);
});
}
});
return false;
});
});
您提供的错误在您的代码中似乎不匹配。你能分享你的整个代码吗? – LinkinTED
@LinkinTED我用整个代码更新了我的帖子 – 112233
控制台说什么?或无?然后尝试添加错误事件,并查看记录了哪些错误。 – LinkinTED