Trying to retrieve the values of name and city in jquery. It seems PHP result is returned as an array in jQuery.
<?php
$val = array(
name => $_POST["name"],
city => $_POST["city"]
);
foreach($val as $res) {
echo $res;
}
?>
$(document).ready(function(){
$.post("get.php",
{
name : "fakename",
city : "fakecity"
},
function(data){
// returns name and city as a single array
alert(data);
// how to get it as an associative array
// desired result :
//* alert(data.name);
//* alert(data.city);
}
);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>