I passed data fetched from database via ajax to be displayed in the html page. I managed to pass it in a multidimensional array from php script. Now I get the json string but I'm unsure on how to properly display the output in a html table.
Script
$("#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 script
$json=array();
array_push($json,array("type"=>$carType,"maker"=>$carMaker));
echo json_encode($json);
Output of data
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"]}]
How do I display this json string in html table?
Output of Datathat you show is not valid JSON.HondaHonda makershould not be there.