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

admin

Administrator
Staff member
I know this question has been asked many times, but in my condition. Firefox is working but chrome is giving me this error:

Code:
Refused to execute script from 'http://localhost:3000/get_all_test_centers?callback=undefined&_=1409807050144' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

I have a wordpress website from where I am sending a REST call to rails server (jsonp request). I made below changes for CORS in RAILS

<strong>mime_types.rb</strong>

Code:
Mime::Type.register 'application/json', :js

<strong>application_controller.rb</strong>

Code:
before_filter :set_access_control_headers
def set_access_control_headers
    headers['Access-Control-Allow-Origin'] = Rails.application.secrets.website_url
    headers['Access-Control-Request-Method'] = 'GET, OPTIONS, HEAD'
    headers['Access-Control-Allow-Headers'] = 'x-requested-with,Content-Type, Authorization'
  end

Code:
Rails.application.secrets.website_url
value is
Code:
http://localhost/

Controller output:

Code:
def get_all_test_centers
test_centers = TestCenter.all
respond_to do |format|
  format.js do
    render :json =&gt; test_centers, :callback =&gt; 'renderTestCenters'
  end
end
end

My wordpress JS:

Code:
var renderTestCenters = function(data) {
    console.log(data);
};

$.ajax({
    url: "http://localhost:3000/get_all_test_centers",
    crossDomain: true,
    type: "GET",
    dataType: "JSONP",
    jsonpCallback: renderTestCenters
});

It works fine in firefox but in chrome it gives me error.