下面是我创建的一个角度服务,用于从 Indeed 职位搜索 api 返回搜索结果:
(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.get("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"
}});
}
}
}());
当发出此调用 http 请求时,我收到以下错误:
XMLHttpRequest 无法加载(url)。请求的资源上不存在“Access-Control-Allow-Origin”标头。起源 'http://本地主机:62510 http://localhost:62510' 因此不允许访问
既然我有 api 密钥,有没有办法绕过这个来取回数据?
我也没有成功地通过 $http.jsonp 调用尝试此操作here https://stackoverflow.com/questions/40311936/http-jsonp-call-from-angular-app-returns-errors
UPDATED我也尝试通过 $.ajax 调用来完成此操作,但这发生在 Angular 范围之外,并且数据永远不会保存到范围变量中。