3

If I run this....

var url = "http://api.ean.com/ean-services/rs/hotel/v3/list?cid=xxx&apiKey=xxx&minorRev=30&currencyCode=AUD";
        $http.jsonp(url)
            .then(function(mycallback){
                $scope.md = mycallback;
                var mydata = mycallback.data; 
                console.log(mydata);            
        });

I get: this error SyntaxError: missing ; before statement

If I change it to get:

 var url = "http://api.ean.com/ean-services/rs/hotel/v3/list?cid=xxx&apiKey=xxx&minorRev=30&currencyCode=AUD";
        $http.get(url)
            .then(function(mycallback){
                $scope.md = mycallback;
                var mydata = mycallback.data; 
                console.log(mydata);            
        });

I get this error SyntaxError:JSON.parse.unexpected end of data at line 1 column 1 of the json data

If I put callback=JSON_CALLBACK at the end it makes no difference. Either which way I can't console.log this endpoint. So stressful.

I have tried other endpoints such as these and these work correctly var url = 'http://jsonplaceholder.typicode.com/posts/1'; var url = "http://www.w3schools.com/angular/customers.php";

enter image description here

It call has succeeded and retruned on the right

6
  • Exactly what line does your error occur on? The console.log call, or before that? Do you have JSON_CALLBACK defined? Can we see the source of that function? Commented Dec 11, 2015 at 14:35
  • It is before that and it is referring to to json file....I don't have JSON_CALLBACK defined Commented Dec 12, 2015 at 1:03
  • If I make a standard get getquest withou jsonp I get this error SyntaxError:JSON.parse.unexpedcted end of data at line 1 column 1 of the jason data Commented Dec 12, 2015 at 3:17
  • What does the data coming back from the ean.com API look like if you access it directly from the browser? The fact that you tried a few example APIs and they returned proper JSON and worked correctly makes me think it could be an issue with the API you are accessing... it may not be returning data in the proper format. Commented Dec 12, 2015 at 4:37
  • Thats what I thought also. I contacted them and they ran it from their end and said it was fine. I have also run the URL in Advanced REST client chrome extension and it returns a valid response Commented Dec 12, 2015 at 5:34

2 Answers 2

0

Please try encoding the URI before passing it to the request. This seems to be the only issue here as we need to encode special characters inside your query string here.

url = encodeURI(url)

Sign up to request clarification or add additional context in comments.

1 Comment

Tried this and the result is the same
0

var url = 'url' + '?callback=JSON_CALLBACK' This will solve the issue

Comments

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.