tomsseisums
tomsseisums

Reputation: 13367

jQuery ajax call gives unexpected error

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, see 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.

Upvotes: 0

Views: 803

Answers (1)

Marcis
Marcis

Reputation: 4617

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);
});

Upvotes: 1

Related Questions