I have some columns in mysqli that I'm reading from PHP. It's fetching and echoing perfectly.
$results = mysqli_fetch_assoc(mysqli_query($conn, $querystring));
echo json_encode($results);
//$results = {"title":"Sea Shells","location":"./Sea Shells.txt","type":"text"}
however, javascript/jquery then reads the echo as a string:
var contentarr = [];
(ajax magic here, success: function(results){
contentarr = results;
});
contentarr[0] = {
contentarr[1] = "
how could I directly read an associative array from PHP and map it to an associative array in Javascript? Jquery is the only library I'm using.
json_[de|en]code()
is JSON.stringify and JSON.parse - medium.com/mindorks/… – ivanivan 1 hour agoheader('Content-Type: application/json');
) in php. – Jeff 1 hour ago