1

Need to fetch the build values from apache.org. So i am using their api https://builds.apache.org/api/json

I tried angularjs $http.jsonp but not able to fetch the data. In chrome console under network json api is getting loaded but the data is not getting returned instead it is throwing the response as error.

app.controller("jsoncontroller",function($scope,$http){
   var url='https://builds.apache.org/api/json';
  $http.jsonp(url).success(function(data){
       console.log('success');
    })
    .error(function () {
      console.log('error')
    });
 });

Getting the error as

Uncaught SyntaxError: Unexpected token : 
error

1 Answer 1

3

As per the jsonp angular docs, you must append JSON_CALLBACK to the URL: https://builds.apache.org/api/json?jsonp=JSON_CALLBACK

However, that URL doesn't work because even when the callback parameter is specified, the server still sends back a content-type of application/json, instead of the expected application/javascript. This causes it to be parsed (evidently) by the json parser instead of the javascript callback needed for JSONP to work. I'm not versed enough in JSONP or Angular to know who is it fault here.

I've made a fiddle with this working with another URL.

[Update]: The apache build server appears to use Jenkins, which has disable JSONP from the remote API. You can verify this yourself by trying to hit their jsonp endpoint, which returns a 403. You'll have to use another endpoint, no way I can see around this.

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

2 Comments

Yes agree, but i need to resolve the error and need to implement with //builds.apache.org/api/json
Any solutions you found?

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.