jquery – how to send database query result in json and display results in javascript? – Education Career Blog

Can any one give me example or reference for converting mysql database query results in to json object and send it to javascript file then parse the json and display results in javascript file using jquery?

Thanks.

,

If you are using PHP, you can use json_encode to convert a PHP array to JSON. Usually mysql results are given in arrays.

Using jQuery, you can give the $.ajax method a dataType of ‘json’, so it will parse the JSON into a JavaScript array for you. (I’m assuming you are using AJAX.)

Or, you can save load the PHP variable in a JS one by doing this:

var sqlResults = <?=$results?>;

I hope this helps.

Leave a Comment