i got an ajax function that calls a php who returns an array:
<?php
$testing = array("one","two","three", "four");
echo json_encode($testing);
?>
i call it with this ajax call;
$.ajax({
url:"ajax_response.php",
type:"POST",
success:function(msg)
{
var array = msg;
var test = array[2];
alert(test);
}
});
the problem is that i want to get array[1] as “one” and im geting 1 character on every array position ex: array[0] = “o”, array[1] = “n”, array[2] = “e”. Its like the json encode or semething is spliting my array variables into characters.
Any help ??
Thanks in advance
You have to parse your answer. Easiest way would be to put a
dataTypeto your AJAX call:Or you can parse it “by hand”. This is sometimes necessary: