Reputation: 27
I'm trying to finish a school project but can't seem to find any solutions. I need to access a database, format the rows into an array, and then return it to a JavaScript file to be used to create a graphic using the Google Charts API.
I can't use PHP since I have to use the school's PHP server which is running PHP 5.1.6. I saw some code that allows you to use JSON on earlier versions of PHP but I'm not sure how to actually add that to my PHP file.
Any suggestions?
Upvotes: 0
Views: 233
Reputation: 8659
Just print out the list of values separated by comma, then use split in Javascript:
var returnVars = xmlhttp.responseText.split(",");
for(var i=0; i<returnVars.length; i++)
{
alert(returnVars[i]);
}
This is assuming an Ajax request. If you're just writing the Javascript into the PHP, obviously its as simple as making the PHP code write out what the Javascript for an array would look like.
Upvotes: 1