1

I am trying to get the JSON object that is created in a remote server and pull it on the page. I have tried every combination with "data type", "type", callback etc but keep getting same "unexpected token :" error.

This is the code that I have tried:

$(function(){
    var url = "http://someurl.com/api/count?url=http://www.yyets.com";
    $.jsonp({
        url: url,
        corsSupport: true, // if URL above supports CORS (optional)
        jsonpSupport: true, // if URL above supports JSONP (optional)
        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 the unexpected token error points to the url:

Uncaught SyntaxError: Unexpected token : http://someurl.com/api/count?url=http://www.yyets.com&_xx1358645456540=1

I also did some error handling with:

error: function (jqXHR, textStatus, errorThrown) {
             if (window.console) console.log("Error... " + textStatus + "        " + errorThrown);

       }

This time it throws,

Uncaught SyntaxError: Unexpected token : count:1
Error... parsererror Error: jQuery19005587419604416937_1358646210172 was not called

Can you please help!!

3
  • there are a number of posts like stackoverflow.com/questions/7936610/… Commented Jan 20, 2013 at 1:54
  • I have tried every recommendation in those tickets. But still no luck. I am really desperate Commented Jan 20, 2013 at 1:59
  • did you figure this out? Commented Mar 27, 2013 at 14:31

1 Answer 1

0

The page which called by javascript have to have that header

header('Access-Control-Allow-Origin: *');
Sign up to request clarification or add additional context in comments.

1 Comment

It has header('Access-Control-Allow-Origin: *'); on the requested page

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.