XMLHttpRequest cannot load file. Cross origin requests are only supported for HTTP

后端 未结 7 1004
太阳男子
太阳男子 2020-11-22 07:08

I am getting the following error:

XMLHttpRequest cannot load file:///C:/Users/richa.agiwal/Desktop/get/rm_Library/templates/template_viewSettings.html. Cross         


        
7条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 07:29

    Simple Solution

    If you are working with pure html/js/css files.

    Install this small server(link) app in chrome. Open the app and point the file location to your project directory.

    Goto the url shown in the app.

    Edit: Smarter solution using Gulp

    Step 1: To install Gulp. Run following command in your terminal.

    npm install gulp-cli -g
    npm install gulp -D
    

    Step 2: Inside your project directory create a file named gulpfile.js. Copy the following content inside it.

    var gulp        = require('gulp');
    var bs          = require('browser-sync').create();   
    
    gulp.task('serve', [], () => {
            bs.init({
                server: {
                   baseDir: "./",
                },
                port: 5000,
                reloadOnRestart: true,
                browser: "google chrome"
            });
            gulp.watch('./**/*', ['', bs.reload]);
    });
    

    Step 3: Install browser sync gulp plugin. Inside the same directory where gulpfile.js is present, run the following command

    npm install browser-sync gulp --save-dev
    

    Step 4: Start the server. Inside the same directory where gulpfile.js is present, run the following command

    gulp serve
    

提交回复
热议问题