Skip to content Skip to sidebar Skip to footer

Jquery Get Request Won't Get Correct Data From Php Echo

I am trying to fill a table using a jquery .get request, the url being a php file. The php gets data from a database, then it should return a json array back to the jquery, array w

Solution 1:

If you look at your JSON data, you can see that there are no keys such as teams or playedgames. This is because you used fetch_row() in the PHP. Change that to fetch_assoc():

while ($row = $result->fetch_assoc()) 

This will give you $row with the field names as keys instead of using numerical keys that fetch_row() provides.

Solution 2:

You can turn the php json into javascript object

obj = JSON.parse(json);

es:

var json='{"ex1":"test","ex2":[{"sub1":"test"},{"sub2":""s2test}],"ex3":true}';
var obj =JSON.parse(json);

after you can acces to data with :

obj.ex1// testobj.ex2[0].sub2//s2test

Post a Comment for "Jquery Get Request Won't Get Correct Data From Php Echo"