2

Below is a angular service I created to return search results from 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"
                }});
             }
         }
}());

When ever this call http request is made i get the following error:

XMLHttpRequest cannot load (url). No 'Access-Control-Allow-Origin' header is present on the requested resoure. Origin 'http://localhost:62510' is therefore not allowed access

Is there a way to bypass this, since I have a api key, to get back data?

I've also unsuccessfully attempted this via a $http.jsonp call here

UPDATED I've tried to accomplish this via $.ajax call also but this happens outside the scope of angular and the data never gets saved to the scope variable.

Community
  • 1
  • 1
aqwright31
  • 169
  • 2
  • 13
  • Is that supposed to be a publicly available GET API? – deceze Oct 27 '16 at 15:32
  • The publisherKey/api key is probably mapped to your hostname. You will probably need to update your host file on your local dev environment with something like 127.0.0.1 localhost.mydomain.com. – Hoyen Oct 27 '16 at 15:34
  • @deceze no but I have a publisher key that gives me access – aqwright31 Oct 27 '16 at 15:35
  • @Hoyen would I then need to pass that address as my "userid"? – aqwright31 Oct 27 '16 at 15:37
  • @aqwright31 No. In your browser instead of http://localhost:62510 you would use http://localhost.mydomain.com:62510 – Hoyen Oct 27 '16 at 15:38
  • I don't see a userid, but only a userip. Since you have the publisher key, they won't need the userid per se. `userip The IP number of the end-user to whom the job results will be displayed. This field is required.` – Mahesh Oct 27 '16 at 15:39
  • I'm sorry I meant userip – aqwright31 Oct 27 '16 at 15:48

0 Answers0