Rovdjuret
Rovdjuret

Reputation: 1528

angularjs jsonp request fails

I'm trying to do a jsonp request to a server. However, I don't seem to get it to work at all...

What I've been trying is to request it using this code:

var deferred = $q.defer();
  $http({
        url: 'http://teacher.standoutcms.se/questions.js/?callback=JSON_CALLBACK',
        method: 'jsonp',
        headers: { 'Content-Type': 'application/javascript' }
    }).success(function(response) {
        deferred.resolve(response);
    }).error(function(response) {
        deferred.reject(response);
    });
  return deferred.promise;

The response I get is an error and it says:

Uncaught ReferenceError: JSON_CALLBACK is not defined questions.js?callback=?:1

I've tried using a regular Jquery and still the same thing happens.

Last but not least I've managed to get it to work with this code:

var url = "http://teacher.standoutcms.se/questions.js?callback=?";
$http.jsonp(url);

$window.JSON_CALLBACK = function(response){
  return response;
}

Only thing here is I cant use success, error or var deferred = $q.defer(); to wait on response...

I've been trying all day, please help me :/

Regards

Upvotes: 0

Views: 377

Answers (1)

maurycy
maurycy

Reputation: 8465

I've it working here http://plnkr.co/edit/Sj4j8kXXAlPCEst0xg3W?p=preview which doesn't throw error but the problem is that the interface you are calling returns wrong MIME, it's text/html but should be application/json i think any workaround would be hacke it's best to contact the developers if you can

Upvotes: 1

Related Questions