0

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

When this executes, it throws this error:

Refused to execute script from (url) because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

This jsonp request should return application/javascript right? I'm confused.

UPDATED

I'm racking my brain with this FYI. Any help would be greatly appreciated...

aqwright31
  • 169
  • 2
  • 13
  • Sending a JSONP request won't change the server's response by itself. The server also has to send back a valid JSONP response. Does the API you're calling support JSONP? You might want to try changing the format to `"format": "jsonp"` just to try it out. – leepowers Oct 28 '16 at 19:27
  • Use `application/javascript` mime type – VadimB Oct 28 '16 at 19:27
  • @leepowers I don't think this API accepts jsonp...I just read the documentation and it only mentions xml and json. I tried doing the same with $http.get but I'm getting a totally different problem [here](http://stackoverflow.com/questions/40288669/rest-api-call-from-angular-app-thowing-errors-to-indeed-api) – aqwright31 Oct 28 '16 at 19:36

1 Answers1

0

Externally set content-type:application/javascript header in the response.

Strict MIME type checking only creates issue in chrome .. however, works fine in firefox.

check this for more ref :

Chrome refuses to execute an AJAX script due to wrong MIME type

You can easily set response header in Php, Java, Node js etc..

Community
  • 1
  • 1
Atul Sharma
  • 9,397
  • 10
  • 38
  • 65