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

prasad.surase

I am a newbie to AngularJS. I am using a rails application to expose data in json format. The data is to be used by angular app. The angular repo and the rails repo are completely different. The reason for different repositories is because I want my rails repo just to expose data using APIs which i can use in the angular app.

My rails controller is as below

class Api::V1::PhonesController < ApplicationController
  def index
    render json: Phone.all
  end

  def show
    render json: Phone.find(params[:id])
  end
  ...
end

Now, when i visit 'localhost:3000/api/v1/phones', it returns me the json data for all the phones. When I visit 'localhost:3000/api/v1/phones/1', it returns the the json data for the phone with id 1. I validated the json data format using http://jsonlint.com/. Everything works fine till here.

My angularjs route file is as:

$routeProvider.
   when('/phones', {
     templateUrl: 'list.html',
     controller: 'PhoneListController' 
   }).
   when('/phones/:id', {
     templateUrl: 'show.html',
     controller: 'PhoneShowController'
   }).
   otherwise({
     redirectTo: '/phones'
   });
}]);

My index.html in the angular repo has the list.html template embedded in it.

<html ng-app='phoneCatApp'>
  ...
</html>
<script type="text/ng-template" id="list.html">
  This is the list template.
</script>

the code for the services.js is as:

var appServices = angular.module('appServices', []);

phoneCatApp.factory('appServices', ['$http', '$q', function($http, $q){
  var url = "http://localhost:3000/api/v1/";

  //get all phones
  this.getPhones = function(){
    var defered = $q.defer();
    var listApi = url + "phones";

    $http.jsonp(listApi).then(function(results){
      defered.resolve(results);
    }, function(error){
      defered.reject(error);
    });
    return defered.promise;
    }
  return this;
}]);

The text in the script template is displayed as well when I visit '#/phones'. The problem is that 1) In chrome, following error is displayed when i inspect the page.

Refused to execute script from 'http://localhost:3000/api/v1/phones' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

2) in firefox, the following error is getting displayed.

SyntaxError: missing ; before statement

Thanks for the help.

urban_raccoons

Hey so I believe your problem is that your rails controller is returning JSON and NOT JSONP. Your controller has to explicitly specify a callback function, which can be specified by the request params.

See Handling jsonp in rails 3 controller for an example of returning JSONP from a rails controller

So your rails code would look like (argh my rails is very very rusty...):

class Api::V1::PhonesController < ApplicationController
  def index
    if params[:callback]
      format.js { render :json => {:phones => Phone.all.to_json}, :callback => params[:callback] }
    else
      format.json { render json: {:phones => Phone.all.to_json}}
    end
end

Then for the angular side, this answer should help you out: parsing JSONP $http.jsonp() response in angular.js

And I think your angular would then look like:

var appServices = angular.module('appServices', []);

phoneCatApp.factory('appServices', ['$http', '$q', function($http, $q){
  var url = "http://localhost:3000/api/v1/";

  //get all phones
  this.getPhones = function(){
    var defered = $q.defer();
    var listApi = url + "phones?callback=JSON_CALLBACK";

    $http.jsonp(listApi).then(function(results){
      defered.resolve(results);
    }, function(error){
      defered.reject(error);
    });
    return defered.promise;
    }
  return this;
}]);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

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

From Dev

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

From Dev

Refused to execute script from 'file_name.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

From Dev

Refused to execute script because strict MIME type checking is enabled

From Dev

Error on minification in console "Refused to execute because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled"

From Dev

Refused to apply style from '' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

Refused to apply style from 'URL' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

Refused to apply style from [Link] because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

"Refused to apply style from because its MIME type "('font/woff2')" is not a supported stylesheet MIME type, and strict MIME checking is enabled"

From Javascript

Refused to execute script, strict MIME type checking is enabled?

From Dev

Refused to execute script from '..../angular.min.js' because its MIME type ('application/octet_stream') is not executable, and strict MIME type check

From Dev

Refused to apply style because its MIME type "text/html" is not supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

(Node Express)Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

Refused to apply style from... because its MIME type ('text/html') is not a supported style-sheet MIME type, and strict MIME checking is enabled

From Dev

Refused to execute script from '*.ts' because its MIME type ('video/vnd.dlna.mpeg-tts') is not executable

From Dev

Refused to execute script from 'url' because its MIME type ('image/jpeg') is not executable

From Dev

MIME type ('application/json') is not executable, and strict MIME type checking is enabled

From Dev

Webpack dev server throws error - Refused to execute script because its MIME type ('text/html') is not executable

From Dev

Importing jQuery plugin into Angular 2+ Refused to execute script because its MIME type ('text/html') is not executable

From Dev

Rewrite requests from loopback to angular2 (Refused to execute script because its MIME type ('text/html') is not executable)

From Dev

Chrome and Spring security: Refused to execute script from 'http://<server url>/assets/app.js' because its MIME type ('') is not executable

From Dev

Tensorboard is showing a blank page (Refused to execute script from 'http://localhost:6006/index.js' because its MIME type)

From Dev

Refused to execute *path_to_bundle* as script because "X-Content-Type: nosniff" was given and its Content-Type is not a script MIME type

From Dev

Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type

From Dev

Refused to apply style from 'http://localhost:3000/style.css' because its MIME type ('text/html')

From Dev

Node refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME

From Javascript

Disable Chrome strict MIME type checking

From Dev

Refused to display style because MIME type

From Dev

Webpack + React.lazy + nested routing: Refused to apply style from '*/css/main.css' because its MIME type ('text/html')

Related Related

  1. 1

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

  2. 2

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

  3. 3

    Refused to execute script from 'file_name.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

  4. 4

    Refused to execute script because strict MIME type checking is enabled

  5. 5

    Error on minification in console "Refused to execute because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled"

  6. 6

    Refused to apply style from '' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

  7. 7

    Refused to apply style from 'URL' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

  8. 8

    Refused to apply style from [Link] because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

  9. 9

    "Refused to apply style from because its MIME type "('font/woff2')" is not a supported stylesheet MIME type, and strict MIME checking is enabled"

  10. 10

    Refused to execute script, strict MIME type checking is enabled?

  11. 11

    Refused to execute script from '..../angular.min.js' because its MIME type ('application/octet_stream') is not executable, and strict MIME type check

  12. 12

    Refused to apply style because its MIME type "text/html" is not supported stylesheet MIME type, and strict MIME checking is enabled

  13. 13

    (Node Express)Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

  14. 14

    Refused to apply style from... because its MIME type ('text/html') is not a supported style-sheet MIME type, and strict MIME checking is enabled

  15. 15

    Refused to execute script from '*.ts' because its MIME type ('video/vnd.dlna.mpeg-tts') is not executable

  16. 16

    Refused to execute script from 'url' because its MIME type ('image/jpeg') is not executable

  17. 17

    MIME type ('application/json') is not executable, and strict MIME type checking is enabled

  18. 18

    Webpack dev server throws error - Refused to execute script because its MIME type ('text/html') is not executable

  19. 19

    Importing jQuery plugin into Angular 2+ Refused to execute script because its MIME type ('text/html') is not executable

  20. 20

    Rewrite requests from loopback to angular2 (Refused to execute script because its MIME type ('text/html') is not executable)

  21. 21

    Chrome and Spring security: Refused to execute script from 'http://<server url>/assets/app.js' because its MIME type ('') is not executable

  22. 22

    Tensorboard is showing a blank page (Refused to execute script from 'http://localhost:6006/index.js' because its MIME type)

  23. 23

    Refused to execute *path_to_bundle* as script because "X-Content-Type: nosniff" was given and its Content-Type is not a script MIME type

  24. 24

    Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type

  25. 25

    Refused to apply style from 'http://localhost:3000/style.css' because its MIME type ('text/html')

  26. 26

    Node refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME

  27. 27

    Disable Chrome strict MIME type checking

  28. 28

    Refused to display style because MIME type

  29. 29

    Webpack + React.lazy + nested routing: Refused to apply style from '*/css/main.css' because its MIME type ('text/html')

HotTag

Archive