I'm trying to loop through the Callback from PHP result.
But I can't or I don't know how to return an array as a Callback
This is my PHP code :
$id = $_GET['id'];
$data = file_get_contents('__url');
parse_str($data);
$array = explode(',', $url_encoded_fmt_stream_map);
foreach($array as $item) {
parse_str($item);
echo $_GET['callback']."(".json_encode($url).");"; // it should return an array at least 3 urls
}
And this is my Jquery code :
$.ajax({
url:"file.php",
dataType: 'jsonp',
data: {id: id},
success:function(response){
$('body').append(response);
}
});
It gives me one result only but it should return an array, it's working like I did not use foreach loop in the php code.
I tested the PHP code without Ajax Request and it returned an array of urls, but if I used the ajax callback it's returning one url only.
$_GET['callback']? Your AJAX post only anid$_GET['callback']means that it came from somewhere. Same as with yourid- you shouldpostit to$_GETit. Your callback is not what you think it is :-)json_encode()?