下面是我创建的角度服务,用于返回来自Indeed job search 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://localhost:62510”来源不允许访问
有没有办法绕过这个,因为我有一个api密钥,以获取数据?
我也通过$ http.jsonp调用here
尝试了此操作失败了已更新 我试图通过$ .ajax调用来实现这一点,但这发生在angular的范围之外,数据永远不会保存到范围变量中。