开发者

jQuery ajax call gives unexpected error

开发者 https://www.devze.com 2023-03-22 19:27 出处:网络
Error recieved (Chrome): Uncaught SyntaxError: Unexpected token : Script, call: var frypeurl = \'http://www.draugiem.lv/say/ext/like_count.php\';

Error recieved (Chrome): Uncaught SyntaxError: Unexpected token :

Script, call:

var frypeurl = 'http://www.draugiem.lv/say/ext/like_count.php';
$.ajax({
    url : frypeurl,
    dataType : 'jsonp',
    crossDomain : true,
    data : { url : 'http://example.com/' },
    headers : { 'Accept' : 'application/json', 'X-Request' : 'JSON' },
    success : function(json){
        console.log(json);
        $('#frypecount').text(json.count);
    }
});

When it's accessed from browser, it returns normal result, se开发者_Python百科e here. ({"count":"0"})

Have no idea what is causing it, tried it before with simply $.getJSON();, but returns same error, hence the headers, crossDomain parameters.

What could be the problem?

One thing I'd like to add, that's the biggest social network here in Latvia, and they have a weird API, functioning wise and coding too, probably. So I still have a guess that it's a problem on their side. I've messaged them, but no response yet.


There is nothing weird. You need to pass callback function by the query string

$.getJSON(frypeurl+"?callback=?", {
  url: "http://example.com/"
}, function(json){
  console.log(json);
  $("#frypecount").text(json.count);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号