I am trying to get a JSON object created on a remote server and pull it onto a page. I tried every combination with "data type", "type", callback, etc., but continued to get the same "unexpected token error:".
This is the code I tried:
$(function(){
var url = "http://someurl.com/api/count?url=http://www.yyets.com";
$.jsonp({
url: url,
corsSupport: true,
jsonpSupport: true,
jsonp:'jsonp',
dataType: 'jsonp',
success: function(data, status){
alert("success");
console.log(data);
},
complete: function(data){
alert('Completed.');
console.log(data);
},
error: function(XHR, textStatus, errorThrown){
alert("ERREUR: " + textStatus);
alert("ERREUR: " + errorThrown);
}
});
});
On the console, an unexpected token error points to a URL:
Uncaught SyntaxError: Unexpected token: http://someurl.com/api/count?url=http://www.yyets.com&_xx1358645456540=1
I also handled some errors:
error: function (jqXHR, textStatus, errorThrown) {
if (window.console) console.log("Error... " + textStatus + " " + errorThrown);
}
This time he throws
Uncaught SyntaxError: Unexpected token: count: 1
Error ... parsererror Error: jQuery19005587419604416937_1358646210172 was not called
Could you help me?