I did some research on how to parse Json into html with jsonp,because the json is on remote domain. But I can't figure out why is this error and how to handle it:
Uncaught SyntaxError: Unexpected token :
This is my code:
$("document").ready(function() {
var url = "http://demos.158.bg/football/apis/eplApiV1.php?action=getRoundListByLeagueID&leagueID=7";
$.getJSON(url + "?callback=?", null, function(jsonp) {
$("#div-my-table").text("<table>");
$.each(data, function(i, item) {
// doing some stuff here
});
$("#div-my-table").append("</table>");
});
});
Thanks in advice.
EDIT: Found solution. For those who will come to this post just make php file on your domain with:
<?php
echo file_get_contents($remote_domain_url);
?>
and include that php file url in getJSON. You will no longer need JSONP. Edited code:
$("document").ready(function() { var url = "http://your.domain/phpfile.php";
$.getJSON(url, null, function(data) {
$("#div-my-table").text("<table>");
$.each(data, function(i, item) {
// doing some stuff here
});
$("#div-my-table").append("</table>");
});
});
You are trying to make a JSONP request, but the server is responding with JSON. You would have to modify the server side code (on
demos.158.bg
) to support JSONP (i.e. look for acallback
argument in the query string and then return anapplication/javascript
document consisting of that value, then(
, then the data, then)
.