After doing a mySQL query in a query.php file, I end up with an array in this format using the json_encode() function.
["A","B", "C"].
However, I'm not really sure about how to use this array with JavaScript on a separate HTML file. After doing some research, here's the script I was able to gather.
$(document).ready(function() {
$.getJSON('query.php', function(data) {
if(data)
{
document.write(data);
alert('success');
}
else
{
alert('error');
}
});
});
My question is, how do I go about copying that PHP array (shown above) into another array I can use with JavaScript? or what's the best alternative to the script shown between the tags?
Thank you
$.getJSON
) to do that. Does what you have not work? – Explosion Pills Feb 18 '13 at 0:33data
is the array. – Felix Kling Feb 18 '13 at 0:46