I want to send an array of Integers from a php file named load.php to a JS script that will in turn send it to a Processing file written in js.
In the load.php i create the array i want to send and send it using json (the array consists of at least 40 Integers):
echo json_encode($varsArray);
In the main php file named game.php is the script:
<script language="JavaScript" type="text/javascript">
function js_GetArray() {
$.get( "load.php", function( actiondata ) {
var obj = JSON.parse(actiondata);
return obj;
});
}
Using this script i request the array from load.php (which I receive in json format), after receiving i parse it and send it back to the processing file.
In the Processing file I receive the array as such:
var objArr;
void setup(){
objArr = js_GetArray();
}
void draw() {
alert(objArr[1]);
}
When activating the alert I receive the error:
Uncaught TypeError: Cannot read property '1' of undefined
How can I solve this and is there a better way to send the array?
Thank you.