0
我有一個Angular $ http的jsonp()函數的問題。我正在嘗試從外部網址獲取一些數據。這是我的代碼:
module.factory('Ajax', function($http) {
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
return {
get: function(url, obj) {
return $http.post(url, obj);
},
getJSON: function(url, obj) {
return $http.jsonp(url, obj);
}
}
});
型號:
factory.getQuote = function(symbol) {
var q = $q.defer();
Ajax.getJSON(
"https://my-url.nl/quote/"+symbol+"/all?callback=parseQuote").then(function(data) {
console.log(data);
q.resolve(data);
}, function(data) {
console.log(data);
console.log("Error Promise getQuote user.js");
});
return q.promise;
}
parseQuote = function(test) {
if (test.status == "OK") {
console.log(test[$scope.symbolCode])
}
}
它得到回調(parseQuote,並記錄我需要的信息),但是,它也記錄 「錯誤承諾的getQuote user.js的」 ,這是在錯誤/失敗回調,這是奇怪的,因爲我得到的數據。
有什麼建議嗎?