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
我在这里工作http://plnkr.co/edit/Sj4j8kXXAlPCEst0xg3W?p=preview不会引发错误,但问题是您调用的接口返回了错误的MIME,它是text/html
但应该是application/json
我认为任何解决方法都无法解决,最好与开发人员联系
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.