0
下面是一個角度的服務,我創建通過JSONP從事實上求職API返回的搜索結果電話http.jsonp返回錯誤
(function() {
"use strict";
angular
.module("career.resources")
.factory("JobSearchService", ["$http", jobsearchService]);
function jobsearchService($http) {
return{
getSearchResults: getSearchResults
};
function getSearchResults(publisherKey,keywords,location,jobType,limit) {
return $http.jsonp("http://api.indeed.com/ads/apisearch?", {params: {
"publisher": publisherKey,
"v": "2",
"format": "json",
"callback": "JSON_CALLBACK",
"q": keywords,
"l": location,
"sort": "",
"radius": "",
"st": "",
"jt": jobType,
"start": "0",
"limit": limit,
"fromage": "",
"highlight": "1",
"filter": "1",
"userip": "1.2.3.4"
}});
}
}
}());
當這個執行,它拋出這個錯誤:
拒絕從(URL)執行腳本,因爲它的MIME類型(「應用/ JSON」)不是可執行文件,並嚴格MIME類型檢查啓用
這JSONP請求應該返回應用程序/ JavaScript的吧?我很困惑。
修訂
我傷透我的大腦與此僅供參考。任何幫助將不勝感激...
發送JSONP請求將不會改變自身服務器的響應。服務器還必須發回有效的JSONP響應。你調用的API是否支持JSONP?您可能想嘗試將格式更改爲'「format」:「jsonp」'只是爲了試用它。 – leepowers
使用'application/javascript' mime類型 – VadimB
@leepowers我不認爲這個API接受jsonp ...我只是閱讀文檔,它只提到xml和json。我試着做同樣的$ http.get,但我得到一個完全不同的問題[這裏](http://stackoverflow.com/questions/40288669/rest-api-call-from-angular-app-thowing-errors -to-確實-API) – aqwright31