I've been attempting to fetch a JavaScript array that was created by a PHP file and reuse the same array in a JavaScript script on my page. Despite trying various solutions found here, none of them seem to be working correctly and I can't figure out what the issue is with my script.
The PHP file echoes the following:
[["content11", "content12", "content13", "content14","content15"],
["content21", "content22", "content23", "content24","content25"]]
I'm using a simple Ajax GET request to retrieve the data:
$.ajax({
type: "GET",
url: myUrlToPhpFile,
dataType: "html",
success : function(data)
{
result = data;
alert (result);
}
});
Although the alert displays the expected output from the PHP file, when I try to access the array using result[0], it only outputs "[" which is the first character. It seems like JavaScript is interpreting the output as a string rather than an array.
Is there something specific I need to do to ensure JavaScript recognizes it as an array?
I've come across many solutions involving JSON arrays, but before diving into that, I'd like to explore simpler options with JavaScript arrays (as this would save me from having to rewrite too much code).
Thanks, Laurent