我通過ajax從數據庫中提取的數據傳遞給html頁面。我設法從php腳本中將它傳遞給一個多維數組。現在我得到了json字符串,但我不確定如何正確顯示html表格中的輸出。數據如何在表中顯示json字符串的多維數組
腳本
$("#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(data);
//hide the form
$("#set_setting").slideUp("slow");
//show the result
/* for (i = 0; i < data.length; i++) {
console.log(data);
$(".the-return").html(data);
}*/
console.log(data);
$(".the-return").html(data);
}
});
return false;
});
});
php腳本
$json=array();
array_push($json,array("type"=>$carType,"maker"=>$carMaker));
echo json_encode($json);
輸出
HondaHonda maker[{"type":["flying car","3 wheleer","weird car","miracle car","tata car","see car","star car","mn car","jkcar","car test","ting","Honda"],"maker":["test maker","diamond car","ruby car","dont know car","titi car","saw car","moon car","ty car","ty car","car maker test","ting maker","Honda maker"]}]
如何顯示HTML表格這個JSON字符串?
那你試過嗎? – donald123
var result = data; ($。parseJSON(result),function(k,v){alert(k +'is'+ v); }); – 112233
那麼這個問題是關於** JS **而不是** PHP ** ?! – donald123