I am sending an array in php (converted from a string using explode), to a seperate javascript page. I was wondering how do I get into the javascript array and actually retrieve data values.
array in javascript (from php file)-
array(2) {
[0]=>
string(2) "30"
[1]=>
string(0) ""
}
array(2) {
[0]=>
string(2) "30"
[1]=>
string(0) ""
}
Here is the ajax call on the javascript page –
$.ajax({
url: "GetTest.php",
type: "POST",
success: function(data){
alert("success");
console.log(data);
},
error: function(data){
alert('failure');
}
});
on the php page –
var_dump((explode(',', $something));
How do I get in here and pull out the “30” value. I am using an ajax call to get this data, and then putting placing this array in a variable called “data”, but if I do something like data[0], I get the letter “a” as a response.
Any help towards this will be greatly appreciated.
Thanks,
A JavaScript array should look like this…
You probably have a string instead of an array if you get an ‘a’ at index 0.
So you need to fix your client side array first.