Im using the following to retrieve a string from php, i would like to know how to make my string into an array.
Jquery
$.get(\"get.php\"
You're already getting back something as useful than an array. Let's say your php does this:
<?php echo json_encode(array('John', 'Mary', 'Joseph')); ?>
Inside your function where you're alerting the data, you can get access to the elements like this:
alert(console.log(data[0])); //will alert "John"
alert(console.log(data[1])); //will alert "Mary"
If you need to loop through any of the elements, you can do so like this:
$(data).each(function(index) {
console.log(this.toString());
});
You are getting JSON out in that callback already. It doesn't look like it because when you "alert" it gets converted to a string that consists of a comma delimited list of the array elements.
You can see this by doing alert(data instanceof Array);
which will spit out "true".