- Impact
- 38
I have looked about the net for help on this but cannot find an example which is unique to this situation.
I want to return the array list from a php file to javascript as an ajax response (using jQuery) for inclusion in a Flot graph.
This is using 'sample' data, the real data will be retrieved from a database and populate $array.
getAccounts.php
accounts.php
The problem I am getting it the PHP is echoing the string 'Array' (which is expected when using echo), if i do 'echo $array[0][0]' it is getting the correct value.
The issue here is how to pass all the $array data into the javascript so it can be read properly.
The line "d = [[-373597200000, 500.71], [-370918800000, 317.45]];" works as required when uncommented so this is the form I need the array inside the JavaScript.
Does anyone know the best way to do this?
Much much appriciated!
I want to return the array list from a php file to javascript as an ajax response (using jQuery) for inclusion in a Flot graph.
This is using 'sample' data, the real data will be retrieved from a database and populate $array.
getAccounts.php
PHP:
$array = array(
0 => array(-373597200000, 315.71),
1 => array(-970918800000, 957.45)
);
echo $array;
accounts.php
PHP:
$(function () {
var d;
$.ajax({
type: "GET",
url: "include/getAccounts.php",
success: function(msg){
d = msg;
}
});
//d = [[-373597200000, 500.71], [-370918800000, 317.45]];
//The array is used here requiring d[i] to populate graph
});
The problem I am getting it the PHP is echoing the string 'Array' (which is expected when using echo), if i do 'echo $array[0][0]' it is getting the correct value.
The issue here is how to pass all the $array data into the javascript so it can be read properly.
The line "d = [[-373597200000, 500.71], [-370918800000, 317.45]];" works as required when uncommented so this is the form I need the array inside the JavaScript.
Does anyone know the best way to do this?
Much much appriciated!