0

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.

15
  • Is your Website in the same domain of frypeurl (draugiem.lv)? Commented Jul 26, 2011 at 12:23
  • @alesdario, no, it's not. P.S. I've updated the url parameter, so you guys can try it out. Commented Jul 26, 2011 at 12:25
  • Have you tried removing the whitespace between url : frypeurl, for example? Could be that Chrome doesn't like it when you have those whitespaces. So it would be url: frypeurl,. Commented Jul 26, 2011 at 12:28
  • 2
    @Tom you can't do cross site AJAX request (it's a security browser setting) Commented Jul 26, 2011 at 12:32
  • 2
    Some of you please write an answer so I can accept it. Commented Jul 26, 2011 at 12:47

1 Answer 1

1

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);
});
Sign up to request clarification or add additional context in comments.

2 Comments

... I'll allow myself not to comment on this situation. Thanks!
I am still getting the same error by both the methods $.ajax({..}) and $.getJSON(..). However i am not passing any url as parameter as you have mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.