Cross origin requests are only supported for HTTP but it's not cross-domain





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







83















I'm using this code to make an AJAX request:



$("#userBarSignup").click(function(){
$.get("C:/xampp/htdocs/webname/resources/templates/signup.php",
{/*params*/},
function(response){
$("#signup").html("TEST");
$("#signup").html(response);
},
"html");


But from the Google Chrome JavaScript console I keep receiving this error:




XMLHttpRequest cannot load
file:///C:/xampp/htdocs/webname/resources/templates/signup.php. Cross
origin requests are only supported for HTTP.




The problem is that the signup.php file is hosted on my local web server that's where all the website is run from so it's not cross-domain.



How can I solve this problem?










share|improve this question




















  • 5





    Have you tried maybe using an HTTP URL instead of a local path?

    – Edward Thomson
    Dec 9 '11 at 18:00






  • 1





    I would suggest using a full url

    – Dominic Green
    Dec 9 '11 at 18:03






  • 1





    @EdwardThomson It worked! But now i have to set allow_url_include = On in my server configuration.

    – siannone
    Dec 9 '11 at 18:05













  • Possible duplicate of "Cross origin requests are only supported for HTTP." error when loading a local file

    – vaxquis
    Jul 8 '17 at 13:06


















83















I'm using this code to make an AJAX request:



$("#userBarSignup").click(function(){
$.get("C:/xampp/htdocs/webname/resources/templates/signup.php",
{/*params*/},
function(response){
$("#signup").html("TEST");
$("#signup").html(response);
},
"html");


But from the Google Chrome JavaScript console I keep receiving this error:




XMLHttpRequest cannot load
file:///C:/xampp/htdocs/webname/resources/templates/signup.php. Cross
origin requests are only supported for HTTP.




The problem is that the signup.php file is hosted on my local web server that's where all the website is run from so it's not cross-domain.



How can I solve this problem?










share|improve this question




















  • 5





    Have you tried maybe using an HTTP URL instead of a local path?

    – Edward Thomson
    Dec 9 '11 at 18:00






  • 1





    I would suggest using a full url

    – Dominic Green
    Dec 9 '11 at 18:03






  • 1





    @EdwardThomson It worked! But now i have to set allow_url_include = On in my server configuration.

    – siannone
    Dec 9 '11 at 18:05













  • Possible duplicate of "Cross origin requests are only supported for HTTP." error when loading a local file

    – vaxquis
    Jul 8 '17 at 13:06














83












83








83


46






I'm using this code to make an AJAX request:



$("#userBarSignup").click(function(){
$.get("C:/xampp/htdocs/webname/resources/templates/signup.php",
{/*params*/},
function(response){
$("#signup").html("TEST");
$("#signup").html(response);
},
"html");


But from the Google Chrome JavaScript console I keep receiving this error:




XMLHttpRequest cannot load
file:///C:/xampp/htdocs/webname/resources/templates/signup.php. Cross
origin requests are only supported for HTTP.




The problem is that the signup.php file is hosted on my local web server that's where all the website is run from so it's not cross-domain.



How can I solve this problem?










share|improve this question
















I'm using this code to make an AJAX request:



$("#userBarSignup").click(function(){
$.get("C:/xampp/htdocs/webname/resources/templates/signup.php",
{/*params*/},
function(response){
$("#signup").html("TEST");
$("#signup").html(response);
},
"html");


But from the Google Chrome JavaScript console I keep receiving this error:




XMLHttpRequest cannot load
file:///C:/xampp/htdocs/webname/resources/templates/signup.php. Cross
origin requests are only supported for HTTP.




The problem is that the signup.php file is hosted on my local web server that's where all the website is run from so it's not cross-domain.



How can I solve this problem?







javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 31 '14 at 21:46









Magnus Lindhe

4,44244157




4,44244157










asked Dec 9 '11 at 17:57









siannonesiannone

3,552114579




3,552114579








  • 5





    Have you tried maybe using an HTTP URL instead of a local path?

    – Edward Thomson
    Dec 9 '11 at 18:00






  • 1





    I would suggest using a full url

    – Dominic Green
    Dec 9 '11 at 18:03






  • 1





    @EdwardThomson It worked! But now i have to set allow_url_include = On in my server configuration.

    – siannone
    Dec 9 '11 at 18:05













  • Possible duplicate of "Cross origin requests are only supported for HTTP." error when loading a local file

    – vaxquis
    Jul 8 '17 at 13:06














  • 5





    Have you tried maybe using an HTTP URL instead of a local path?

    – Edward Thomson
    Dec 9 '11 at 18:00






  • 1





    I would suggest using a full url

    – Dominic Green
    Dec 9 '11 at 18:03






  • 1





    @EdwardThomson It worked! But now i have to set allow_url_include = On in my server configuration.

    – siannone
    Dec 9 '11 at 18:05













  • Possible duplicate of "Cross origin requests are only supported for HTTP." error when loading a local file

    – vaxquis
    Jul 8 '17 at 13:06








5




5





Have you tried maybe using an HTTP URL instead of a local path?

– Edward Thomson
Dec 9 '11 at 18:00





Have you tried maybe using an HTTP URL instead of a local path?

– Edward Thomson
Dec 9 '11 at 18:00




1




1





I would suggest using a full url

– Dominic Green
Dec 9 '11 at 18:03





I would suggest using a full url

– Dominic Green
Dec 9 '11 at 18:03




1




1





@EdwardThomson It worked! But now i have to set allow_url_include = On in my server configuration.

– siannone
Dec 9 '11 at 18:05







@EdwardThomson It worked! But now i have to set allow_url_include = On in my server configuration.

– siannone
Dec 9 '11 at 18:05















Possible duplicate of "Cross origin requests are only supported for HTTP." error when loading a local file

– vaxquis
Jul 8 '17 at 13:06





Possible duplicate of "Cross origin requests are only supported for HTTP." error when loading a local file

– vaxquis
Jul 8 '17 at 13:06












6 Answers
6






active

oldest

votes


















73














You need to actually run a webserver, and make the get request to a URI on that server, rather than making the get request to a file; e.g. change the line:



    $.get("C:/xampp/htdocs/webname/resources/templates/signup.php",


to read something like:



    $.get("http://localhost/resources/templates/signup.php",


and the initial request page needs to be made over http as well.






share|improve this answer
























  • This worked like a charm. Now i have to set allow_url_include = On in my server configuration. Can i safely enable it or it will cause some safety issues?

    – siannone
    Dec 9 '11 at 18:07













  • The $.get is actually issued in the javascript context of the web browser, so that file needs to have the URL reference - code that is written in php can still reference local files without issue

    – Petesh
    Dec 10 '11 at 15:25






  • 41





    Alternatively there's the Python solution: (1) navigate a console to the folder, (2) enter python -m SimpleHTTPServer 8888, then (3) navigate browser to http://localhost:8888/

    – geotheory
    Nov 4 '13 at 2:15











  • +1 this helped a lot to resolve my problem. Thanks a lot :)

    – Praveen
    Nov 8 '13 at 19:27






  • 4





    Note for Python 3 users: use python -m http.server 8888

    – Jelle Fresen
    Jul 25 '15 at 0:50



















106














I've had luck starting chrome with the following switch:



--allow-file-access-from-files


On os x try (re-type the dashes if you copy paste):



open -a 'Google Chrome' --args -allow-file-access-from-files


On other *nix run (not tested)



 google-chrome  --allow-file-access-from-files


or on windows edit the properties of the chrome shortcut and add the switch, e.g.



 C: ... Applicationchrome.exe --allow-file-access-from-files


to the end of the "target" path






share|improve this answer





















  • 7





    Works in Google Chrome (at least as of v24) in principle, but note that on OS X you must invoke it as follows: open -a 'Google Chrome' --args —allow-file-access-from-files. Also note: If you specify a file://-based URL (rather than a file-system path), be sure to use file://localhost/... rather than file:///....

    – mklement0
    Jan 29 '13 at 22:37






  • 6





    Last time I tried to do this in windows the method above didn't work. I ended up having to launch chrome from the DOS prompt with the switch following... Imperfect but workable.

    – prauchfuss
    Dec 23 '13 at 19:49











  • Works great on Linux.

    – user1205577
    Sep 16 '14 at 14:35











  • Works fine on OS X Yosemite 10.10.2 and Chrome Version 41.0.2272.89 (64-bit).

    – The Dude
    Mar 15 '15 at 13:14



















83














If you’re working on a little front-end project and want to test it locally, you’d typically open it by pointing your local directory in the web browser, for instance entering file:///home/erick/mysuperproject/index.html in your URL bar. However, if your site is trying to load resources, even if they’re placed in your local directory, you might see warnings like this:



XMLHttpRequest cannot load file:///home/erick/mysuperproject/mylibrary.js. Cross origin requests are only supported for HTTP.



Chrome and other modern browsers have implemented security restrictions for Cross Origin Requests, which means that you cannot load anything through file:/// , you need to use http:// protocol at all times, even locally -due Same Origin policies. Simple as that, you’d need to mount a webserver to run your project there.



This is not the end of the world and there are many solutions out there, including the good old Apache (with VirtualHosts if you’re running several other projects), node.js with express, a Ruby server, etc. or simply modifying your browser settings.



However there’s a simpler and lightweight solution for the lazy ones. You can use Python’s SimpleHTTPServer. It comes already bundled with python so you don’t need to install or configure anything at all!



So cd to your project directory, for instance



1
cd /home/erick/mysuperproject
and then simply use



1
python -m SimpleHTTPServer
And that’s it, you’ll see this message in your terminal



1
Serving HTTP on 0.0.0.0 port 8000 ...
So now you can go back to your browser and visit http://0.0.0.0:8000 with all your directory files served there. You can configure the port and other things, just see the documentation. But this simply trick works for me when I’m in a rush to test a new library or work out a new idea.



There you go, happy coding!



EDIT:
In Python 3+, SimpleHTTPServer has been replaced with http.server. So In Python 3.3, for example, the following command is equivalent:



python -m http.server 8000





share|improve this answer





















  • 5





    The lazy solution is awesome. Very straightforward, you don't need to do anything else.

    – Nico
    Apr 23 '14 at 4:24






  • 1





    You sir you deserve more votes. Very good answer!

    – Havok
    Jun 27 '14 at 3:34











  • equivalent exist in node.js also : simple-http-server

    – StackHola
    Jul 29 '14 at 22:06











  • On Windows 8.1, You'd still have to install Python no?

    – J86
    Oct 13 '14 at 8:21











  • I use Xampp on windows, it's simple, tho I'd recommend using node, also don't forget to unblock port 80 on skype to allow the server to run

    – Timo Huovinen
    Feb 22 '17 at 11:06





















9














I was getting the same error while trying to load simply HTML files that used JSON data to populate the page, so I used used node.js and express to solve the problem. If you do not have node installed, you need to install node first.




  1. Install express
    npm install express


  2. Create a server.js file in the root folder of your project, in my case one folder above the files I wanted to server



  3. Put something like the following in the server.js file and read about this on the express gihub site:



    var express = require('express');
    var app = express();
    var path = require('path');

    // __dirname will use the current path from where you run this file
    app.use(express.static(__dirname));
    app.use(express.static(path.join(__dirname, '/FOLDERTOHTMLFILESTOSERVER')));

    app.listen(8000);
    console.log('Listening on port 8000');


  4. After you've saved server.js, you can run the server using:



node server.js




  1. Go to http://localhost:8000/FILENAME and you should see the HTML file you were trying to load






share|improve this answer

































    2














    If you have nodejs installed, you can download and install the server using command line:



    npm install -g http-server


    Change directories to the directory where you want to serve files from:



    $ cd ~/projects/angular/current_project 


    Run the server:



    $ http-server 


    which will produce the message Starting up http-server, serving on:



    Available on:
    http://your_ip:8080 and
    http://127.0.0.1:8080



    That allows you to use urls in your browser like




    http://your_ip:8080/index.html







    share|improve this answer































      1














      It works best this way. Make sure that both files are on the server. When calling the html page, make use of the web address like: http:://localhost/myhtmlfile.html, and not, C::///users/myhtmlfile.html. Make usre as well that the url passed to the json is a web address as denoted below:



      $(function(){
      $('#typeahead').typeahead({
      source: function(query, process){
      $.ajax({
      url: 'http://localhost:2222/bootstrap/source.php',
      type: 'POST',
      data: 'query=' +query,
      dataType: 'JSON',
      async: true,
      success: function(data){
      process(data);
      }
      });
      }
      });
      });





      share|improve this answer
























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8449716%2fcross-origin-requests-are-only-supported-for-http-but-its-not-cross-domain%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        73














        You need to actually run a webserver, and make the get request to a URI on that server, rather than making the get request to a file; e.g. change the line:



            $.get("C:/xampp/htdocs/webname/resources/templates/signup.php",


        to read something like:



            $.get("http://localhost/resources/templates/signup.php",


        and the initial request page needs to be made over http as well.






        share|improve this answer
























        • This worked like a charm. Now i have to set allow_url_include = On in my server configuration. Can i safely enable it or it will cause some safety issues?

          – siannone
          Dec 9 '11 at 18:07













        • The $.get is actually issued in the javascript context of the web browser, so that file needs to have the URL reference - code that is written in php can still reference local files without issue

          – Petesh
          Dec 10 '11 at 15:25






        • 41





          Alternatively there's the Python solution: (1) navigate a console to the folder, (2) enter python -m SimpleHTTPServer 8888, then (3) navigate browser to http://localhost:8888/

          – geotheory
          Nov 4 '13 at 2:15











        • +1 this helped a lot to resolve my problem. Thanks a lot :)

          – Praveen
          Nov 8 '13 at 19:27






        • 4





          Note for Python 3 users: use python -m http.server 8888

          – Jelle Fresen
          Jul 25 '15 at 0:50
















        73














        You need to actually run a webserver, and make the get request to a URI on that server, rather than making the get request to a file; e.g. change the line:



            $.get("C:/xampp/htdocs/webname/resources/templates/signup.php",


        to read something like:



            $.get("http://localhost/resources/templates/signup.php",


        and the initial request page needs to be made over http as well.






        share|improve this answer
























        • This worked like a charm. Now i have to set allow_url_include = On in my server configuration. Can i safely enable it or it will cause some safety issues?

          – siannone
          Dec 9 '11 at 18:07













        • The $.get is actually issued in the javascript context of the web browser, so that file needs to have the URL reference - code that is written in php can still reference local files without issue

          – Petesh
          Dec 10 '11 at 15:25






        • 41





          Alternatively there's the Python solution: (1) navigate a console to the folder, (2) enter python -m SimpleHTTPServer 8888, then (3) navigate browser to http://localhost:8888/

          – geotheory
          Nov 4 '13 at 2:15











        • +1 this helped a lot to resolve my problem. Thanks a lot :)

          – Praveen
          Nov 8 '13 at 19:27






        • 4





          Note for Python 3 users: use python -m http.server 8888

          – Jelle Fresen
          Jul 25 '15 at 0:50














        73












        73








        73







        You need to actually run a webserver, and make the get request to a URI on that server, rather than making the get request to a file; e.g. change the line:



            $.get("C:/xampp/htdocs/webname/resources/templates/signup.php",


        to read something like:



            $.get("http://localhost/resources/templates/signup.php",


        and the initial request page needs to be made over http as well.






        share|improve this answer













        You need to actually run a webserver, and make the get request to a URI on that server, rather than making the get request to a file; e.g. change the line:



            $.get("C:/xampp/htdocs/webname/resources/templates/signup.php",


        to read something like:



            $.get("http://localhost/resources/templates/signup.php",


        and the initial request page needs to be made over http as well.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 9 '11 at 18:02









        PeteshPetesh

        70.7k37497




        70.7k37497













        • This worked like a charm. Now i have to set allow_url_include = On in my server configuration. Can i safely enable it or it will cause some safety issues?

          – siannone
          Dec 9 '11 at 18:07













        • The $.get is actually issued in the javascript context of the web browser, so that file needs to have the URL reference - code that is written in php can still reference local files without issue

          – Petesh
          Dec 10 '11 at 15:25






        • 41





          Alternatively there's the Python solution: (1) navigate a console to the folder, (2) enter python -m SimpleHTTPServer 8888, then (3) navigate browser to http://localhost:8888/

          – geotheory
          Nov 4 '13 at 2:15











        • +1 this helped a lot to resolve my problem. Thanks a lot :)

          – Praveen
          Nov 8 '13 at 19:27






        • 4





          Note for Python 3 users: use python -m http.server 8888

          – Jelle Fresen
          Jul 25 '15 at 0:50



















        • This worked like a charm. Now i have to set allow_url_include = On in my server configuration. Can i safely enable it or it will cause some safety issues?

          – siannone
          Dec 9 '11 at 18:07













        • The $.get is actually issued in the javascript context of the web browser, so that file needs to have the URL reference - code that is written in php can still reference local files without issue

          – Petesh
          Dec 10 '11 at 15:25






        • 41





          Alternatively there's the Python solution: (1) navigate a console to the folder, (2) enter python -m SimpleHTTPServer 8888, then (3) navigate browser to http://localhost:8888/

          – geotheory
          Nov 4 '13 at 2:15











        • +1 this helped a lot to resolve my problem. Thanks a lot :)

          – Praveen
          Nov 8 '13 at 19:27






        • 4





          Note for Python 3 users: use python -m http.server 8888

          – Jelle Fresen
          Jul 25 '15 at 0:50

















        This worked like a charm. Now i have to set allow_url_include = On in my server configuration. Can i safely enable it or it will cause some safety issues?

        – siannone
        Dec 9 '11 at 18:07







        This worked like a charm. Now i have to set allow_url_include = On in my server configuration. Can i safely enable it or it will cause some safety issues?

        – siannone
        Dec 9 '11 at 18:07















        The $.get is actually issued in the javascript context of the web browser, so that file needs to have the URL reference - code that is written in php can still reference local files without issue

        – Petesh
        Dec 10 '11 at 15:25





        The $.get is actually issued in the javascript context of the web browser, so that file needs to have the URL reference - code that is written in php can still reference local files without issue

        – Petesh
        Dec 10 '11 at 15:25




        41




        41





        Alternatively there's the Python solution: (1) navigate a console to the folder, (2) enter python -m SimpleHTTPServer 8888, then (3) navigate browser to http://localhost:8888/

        – geotheory
        Nov 4 '13 at 2:15





        Alternatively there's the Python solution: (1) navigate a console to the folder, (2) enter python -m SimpleHTTPServer 8888, then (3) navigate browser to http://localhost:8888/

        – geotheory
        Nov 4 '13 at 2:15













        +1 this helped a lot to resolve my problem. Thanks a lot :)

        – Praveen
        Nov 8 '13 at 19:27





        +1 this helped a lot to resolve my problem. Thanks a lot :)

        – Praveen
        Nov 8 '13 at 19:27




        4




        4





        Note for Python 3 users: use python -m http.server 8888

        – Jelle Fresen
        Jul 25 '15 at 0:50





        Note for Python 3 users: use python -m http.server 8888

        – Jelle Fresen
        Jul 25 '15 at 0:50













        106














        I've had luck starting chrome with the following switch:



        --allow-file-access-from-files


        On os x try (re-type the dashes if you copy paste):



        open -a 'Google Chrome' --args -allow-file-access-from-files


        On other *nix run (not tested)



         google-chrome  --allow-file-access-from-files


        or on windows edit the properties of the chrome shortcut and add the switch, e.g.



         C: ... Applicationchrome.exe --allow-file-access-from-files


        to the end of the "target" path






        share|improve this answer





















        • 7





          Works in Google Chrome (at least as of v24) in principle, but note that on OS X you must invoke it as follows: open -a 'Google Chrome' --args —allow-file-access-from-files. Also note: If you specify a file://-based URL (rather than a file-system path), be sure to use file://localhost/... rather than file:///....

          – mklement0
          Jan 29 '13 at 22:37






        • 6





          Last time I tried to do this in windows the method above didn't work. I ended up having to launch chrome from the DOS prompt with the switch following... Imperfect but workable.

          – prauchfuss
          Dec 23 '13 at 19:49











        • Works great on Linux.

          – user1205577
          Sep 16 '14 at 14:35











        • Works fine on OS X Yosemite 10.10.2 and Chrome Version 41.0.2272.89 (64-bit).

          – The Dude
          Mar 15 '15 at 13:14
















        106














        I've had luck starting chrome with the following switch:



        --allow-file-access-from-files


        On os x try (re-type the dashes if you copy paste):



        open -a 'Google Chrome' --args -allow-file-access-from-files


        On other *nix run (not tested)



         google-chrome  --allow-file-access-from-files


        or on windows edit the properties of the chrome shortcut and add the switch, e.g.



         C: ... Applicationchrome.exe --allow-file-access-from-files


        to the end of the "target" path






        share|improve this answer





















        • 7





          Works in Google Chrome (at least as of v24) in principle, but note that on OS X you must invoke it as follows: open -a 'Google Chrome' --args —allow-file-access-from-files. Also note: If you specify a file://-based URL (rather than a file-system path), be sure to use file://localhost/... rather than file:///....

          – mklement0
          Jan 29 '13 at 22:37






        • 6





          Last time I tried to do this in windows the method above didn't work. I ended up having to launch chrome from the DOS prompt with the switch following... Imperfect but workable.

          – prauchfuss
          Dec 23 '13 at 19:49











        • Works great on Linux.

          – user1205577
          Sep 16 '14 at 14:35











        • Works fine on OS X Yosemite 10.10.2 and Chrome Version 41.0.2272.89 (64-bit).

          – The Dude
          Mar 15 '15 at 13:14














        106












        106








        106







        I've had luck starting chrome with the following switch:



        --allow-file-access-from-files


        On os x try (re-type the dashes if you copy paste):



        open -a 'Google Chrome' --args -allow-file-access-from-files


        On other *nix run (not tested)



         google-chrome  --allow-file-access-from-files


        or on windows edit the properties of the chrome shortcut and add the switch, e.g.



         C: ... Applicationchrome.exe --allow-file-access-from-files


        to the end of the "target" path






        share|improve this answer















        I've had luck starting chrome with the following switch:



        --allow-file-access-from-files


        On os x try (re-type the dashes if you copy paste):



        open -a 'Google Chrome' --args -allow-file-access-from-files


        On other *nix run (not tested)



         google-chrome  --allow-file-access-from-files


        or on windows edit the properties of the chrome shortcut and add the switch, e.g.



         C: ... Applicationchrome.exe --allow-file-access-from-files


        to the end of the "target" path







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 17 '13 at 18:03

























        answered Jan 23 '13 at 22:58









        prauchfussprauchfuss

        1,48711518




        1,48711518








        • 7





          Works in Google Chrome (at least as of v24) in principle, but note that on OS X you must invoke it as follows: open -a 'Google Chrome' --args —allow-file-access-from-files. Also note: If you specify a file://-based URL (rather than a file-system path), be sure to use file://localhost/... rather than file:///....

          – mklement0
          Jan 29 '13 at 22:37






        • 6





          Last time I tried to do this in windows the method above didn't work. I ended up having to launch chrome from the DOS prompt with the switch following... Imperfect but workable.

          – prauchfuss
          Dec 23 '13 at 19:49











        • Works great on Linux.

          – user1205577
          Sep 16 '14 at 14:35











        • Works fine on OS X Yosemite 10.10.2 and Chrome Version 41.0.2272.89 (64-bit).

          – The Dude
          Mar 15 '15 at 13:14














        • 7





          Works in Google Chrome (at least as of v24) in principle, but note that on OS X you must invoke it as follows: open -a 'Google Chrome' --args —allow-file-access-from-files. Also note: If you specify a file://-based URL (rather than a file-system path), be sure to use file://localhost/... rather than file:///....

          – mklement0
          Jan 29 '13 at 22:37






        • 6





          Last time I tried to do this in windows the method above didn't work. I ended up having to launch chrome from the DOS prompt with the switch following... Imperfect but workable.

          – prauchfuss
          Dec 23 '13 at 19:49











        • Works great on Linux.

          – user1205577
          Sep 16 '14 at 14:35











        • Works fine on OS X Yosemite 10.10.2 and Chrome Version 41.0.2272.89 (64-bit).

          – The Dude
          Mar 15 '15 at 13:14








        7




        7





        Works in Google Chrome (at least as of v24) in principle, but note that on OS X you must invoke it as follows: open -a 'Google Chrome' --args —allow-file-access-from-files. Also note: If you specify a file://-based URL (rather than a file-system path), be sure to use file://localhost/... rather than file:///....

        – mklement0
        Jan 29 '13 at 22:37





        Works in Google Chrome (at least as of v24) in principle, but note that on OS X you must invoke it as follows: open -a 'Google Chrome' --args —allow-file-access-from-files. Also note: If you specify a file://-based URL (rather than a file-system path), be sure to use file://localhost/... rather than file:///....

        – mklement0
        Jan 29 '13 at 22:37




        6




        6





        Last time I tried to do this in windows the method above didn't work. I ended up having to launch chrome from the DOS prompt with the switch following... Imperfect but workable.

        – prauchfuss
        Dec 23 '13 at 19:49





        Last time I tried to do this in windows the method above didn't work. I ended up having to launch chrome from the DOS prompt with the switch following... Imperfect but workable.

        – prauchfuss
        Dec 23 '13 at 19:49













        Works great on Linux.

        – user1205577
        Sep 16 '14 at 14:35





        Works great on Linux.

        – user1205577
        Sep 16 '14 at 14:35













        Works fine on OS X Yosemite 10.10.2 and Chrome Version 41.0.2272.89 (64-bit).

        – The Dude
        Mar 15 '15 at 13:14





        Works fine on OS X Yosemite 10.10.2 and Chrome Version 41.0.2272.89 (64-bit).

        – The Dude
        Mar 15 '15 at 13:14











        83














        If you’re working on a little front-end project and want to test it locally, you’d typically open it by pointing your local directory in the web browser, for instance entering file:///home/erick/mysuperproject/index.html in your URL bar. However, if your site is trying to load resources, even if they’re placed in your local directory, you might see warnings like this:



        XMLHttpRequest cannot load file:///home/erick/mysuperproject/mylibrary.js. Cross origin requests are only supported for HTTP.



        Chrome and other modern browsers have implemented security restrictions for Cross Origin Requests, which means that you cannot load anything through file:/// , you need to use http:// protocol at all times, even locally -due Same Origin policies. Simple as that, you’d need to mount a webserver to run your project there.



        This is not the end of the world and there are many solutions out there, including the good old Apache (with VirtualHosts if you’re running several other projects), node.js with express, a Ruby server, etc. or simply modifying your browser settings.



        However there’s a simpler and lightweight solution for the lazy ones. You can use Python’s SimpleHTTPServer. It comes already bundled with python so you don’t need to install or configure anything at all!



        So cd to your project directory, for instance



        1
        cd /home/erick/mysuperproject
        and then simply use



        1
        python -m SimpleHTTPServer
        And that’s it, you’ll see this message in your terminal



        1
        Serving HTTP on 0.0.0.0 port 8000 ...
        So now you can go back to your browser and visit http://0.0.0.0:8000 with all your directory files served there. You can configure the port and other things, just see the documentation. But this simply trick works for me when I’m in a rush to test a new library or work out a new idea.



        There you go, happy coding!



        EDIT:
        In Python 3+, SimpleHTTPServer has been replaced with http.server. So In Python 3.3, for example, the following command is equivalent:



        python -m http.server 8000





        share|improve this answer





















        • 5





          The lazy solution is awesome. Very straightforward, you don't need to do anything else.

          – Nico
          Apr 23 '14 at 4:24






        • 1





          You sir you deserve more votes. Very good answer!

          – Havok
          Jun 27 '14 at 3:34











        • equivalent exist in node.js also : simple-http-server

          – StackHola
          Jul 29 '14 at 22:06











        • On Windows 8.1, You'd still have to install Python no?

          – J86
          Oct 13 '14 at 8:21











        • I use Xampp on windows, it's simple, tho I'd recommend using node, also don't forget to unblock port 80 on skype to allow the server to run

          – Timo Huovinen
          Feb 22 '17 at 11:06


















        83














        If you’re working on a little front-end project and want to test it locally, you’d typically open it by pointing your local directory in the web browser, for instance entering file:///home/erick/mysuperproject/index.html in your URL bar. However, if your site is trying to load resources, even if they’re placed in your local directory, you might see warnings like this:



        XMLHttpRequest cannot load file:///home/erick/mysuperproject/mylibrary.js. Cross origin requests are only supported for HTTP.



        Chrome and other modern browsers have implemented security restrictions for Cross Origin Requests, which means that you cannot load anything through file:/// , you need to use http:// protocol at all times, even locally -due Same Origin policies. Simple as that, you’d need to mount a webserver to run your project there.



        This is not the end of the world and there are many solutions out there, including the good old Apache (with VirtualHosts if you’re running several other projects), node.js with express, a Ruby server, etc. or simply modifying your browser settings.



        However there’s a simpler and lightweight solution for the lazy ones. You can use Python’s SimpleHTTPServer. It comes already bundled with python so you don’t need to install or configure anything at all!



        So cd to your project directory, for instance



        1
        cd /home/erick/mysuperproject
        and then simply use



        1
        python -m SimpleHTTPServer
        And that’s it, you’ll see this message in your terminal



        1
        Serving HTTP on 0.0.0.0 port 8000 ...
        So now you can go back to your browser and visit http://0.0.0.0:8000 with all your directory files served there. You can configure the port and other things, just see the documentation. But this simply trick works for me when I’m in a rush to test a new library or work out a new idea.



        There you go, happy coding!



        EDIT:
        In Python 3+, SimpleHTTPServer has been replaced with http.server. So In Python 3.3, for example, the following command is equivalent:



        python -m http.server 8000





        share|improve this answer





















        • 5





          The lazy solution is awesome. Very straightforward, you don't need to do anything else.

          – Nico
          Apr 23 '14 at 4:24






        • 1





          You sir you deserve more votes. Very good answer!

          – Havok
          Jun 27 '14 at 3:34











        • equivalent exist in node.js also : simple-http-server

          – StackHola
          Jul 29 '14 at 22:06











        • On Windows 8.1, You'd still have to install Python no?

          – J86
          Oct 13 '14 at 8:21











        • I use Xampp on windows, it's simple, tho I'd recommend using node, also don't forget to unblock port 80 on skype to allow the server to run

          – Timo Huovinen
          Feb 22 '17 at 11:06
















        83












        83








        83







        If you’re working on a little front-end project and want to test it locally, you’d typically open it by pointing your local directory in the web browser, for instance entering file:///home/erick/mysuperproject/index.html in your URL bar. However, if your site is trying to load resources, even if they’re placed in your local directory, you might see warnings like this:



        XMLHttpRequest cannot load file:///home/erick/mysuperproject/mylibrary.js. Cross origin requests are only supported for HTTP.



        Chrome and other modern browsers have implemented security restrictions for Cross Origin Requests, which means that you cannot load anything through file:/// , you need to use http:// protocol at all times, even locally -due Same Origin policies. Simple as that, you’d need to mount a webserver to run your project there.



        This is not the end of the world and there are many solutions out there, including the good old Apache (with VirtualHosts if you’re running several other projects), node.js with express, a Ruby server, etc. or simply modifying your browser settings.



        However there’s a simpler and lightweight solution for the lazy ones. You can use Python’s SimpleHTTPServer. It comes already bundled with python so you don’t need to install or configure anything at all!



        So cd to your project directory, for instance



        1
        cd /home/erick/mysuperproject
        and then simply use



        1
        python -m SimpleHTTPServer
        And that’s it, you’ll see this message in your terminal



        1
        Serving HTTP on 0.0.0.0 port 8000 ...
        So now you can go back to your browser and visit http://0.0.0.0:8000 with all your directory files served there. You can configure the port and other things, just see the documentation. But this simply trick works for me when I’m in a rush to test a new library or work out a new idea.



        There you go, happy coding!



        EDIT:
        In Python 3+, SimpleHTTPServer has been replaced with http.server. So In Python 3.3, for example, the following command is equivalent:



        python -m http.server 8000





        share|improve this answer















        If you’re working on a little front-end project and want to test it locally, you’d typically open it by pointing your local directory in the web browser, for instance entering file:///home/erick/mysuperproject/index.html in your URL bar. However, if your site is trying to load resources, even if they’re placed in your local directory, you might see warnings like this:



        XMLHttpRequest cannot load file:///home/erick/mysuperproject/mylibrary.js. Cross origin requests are only supported for HTTP.



        Chrome and other modern browsers have implemented security restrictions for Cross Origin Requests, which means that you cannot load anything through file:/// , you need to use http:// protocol at all times, even locally -due Same Origin policies. Simple as that, you’d need to mount a webserver to run your project there.



        This is not the end of the world and there are many solutions out there, including the good old Apache (with VirtualHosts if you’re running several other projects), node.js with express, a Ruby server, etc. or simply modifying your browser settings.



        However there’s a simpler and lightweight solution for the lazy ones. You can use Python’s SimpleHTTPServer. It comes already bundled with python so you don’t need to install or configure anything at all!



        So cd to your project directory, for instance



        1
        cd /home/erick/mysuperproject
        and then simply use



        1
        python -m SimpleHTTPServer
        And that’s it, you’ll see this message in your terminal



        1
        Serving HTTP on 0.0.0.0 port 8000 ...
        So now you can go back to your browser and visit http://0.0.0.0:8000 with all your directory files served there. You can configure the port and other things, just see the documentation. But this simply trick works for me when I’m in a rush to test a new library or work out a new idea.



        There you go, happy coding!



        EDIT:
        In Python 3+, SimpleHTTPServer has been replaced with http.server. So In Python 3.3, for example, the following command is equivalent:



        python -m http.server 8000






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 2 '14 at 22:08









        Jpnh

        6111819




        6111819










        answered Apr 16 '14 at 19:39









        Pramod AlagambhatPramod Alagambhat

        1,2931010




        1,2931010








        • 5





          The lazy solution is awesome. Very straightforward, you don't need to do anything else.

          – Nico
          Apr 23 '14 at 4:24






        • 1





          You sir you deserve more votes. Very good answer!

          – Havok
          Jun 27 '14 at 3:34











        • equivalent exist in node.js also : simple-http-server

          – StackHola
          Jul 29 '14 at 22:06











        • On Windows 8.1, You'd still have to install Python no?

          – J86
          Oct 13 '14 at 8:21











        • I use Xampp on windows, it's simple, tho I'd recommend using node, also don't forget to unblock port 80 on skype to allow the server to run

          – Timo Huovinen
          Feb 22 '17 at 11:06
















        • 5





          The lazy solution is awesome. Very straightforward, you don't need to do anything else.

          – Nico
          Apr 23 '14 at 4:24






        • 1





          You sir you deserve more votes. Very good answer!

          – Havok
          Jun 27 '14 at 3:34











        • equivalent exist in node.js also : simple-http-server

          – StackHola
          Jul 29 '14 at 22:06











        • On Windows 8.1, You'd still have to install Python no?

          – J86
          Oct 13 '14 at 8:21











        • I use Xampp on windows, it's simple, tho I'd recommend using node, also don't forget to unblock port 80 on skype to allow the server to run

          – Timo Huovinen
          Feb 22 '17 at 11:06










        5




        5





        The lazy solution is awesome. Very straightforward, you don't need to do anything else.

        – Nico
        Apr 23 '14 at 4:24





        The lazy solution is awesome. Very straightforward, you don't need to do anything else.

        – Nico
        Apr 23 '14 at 4:24




        1




        1





        You sir you deserve more votes. Very good answer!

        – Havok
        Jun 27 '14 at 3:34





        You sir you deserve more votes. Very good answer!

        – Havok
        Jun 27 '14 at 3:34













        equivalent exist in node.js also : simple-http-server

        – StackHola
        Jul 29 '14 at 22:06





        equivalent exist in node.js also : simple-http-server

        – StackHola
        Jul 29 '14 at 22:06













        On Windows 8.1, You'd still have to install Python no?

        – J86
        Oct 13 '14 at 8:21





        On Windows 8.1, You'd still have to install Python no?

        – J86
        Oct 13 '14 at 8:21













        I use Xampp on windows, it's simple, tho I'd recommend using node, also don't forget to unblock port 80 on skype to allow the server to run

        – Timo Huovinen
        Feb 22 '17 at 11:06







        I use Xampp on windows, it's simple, tho I'd recommend using node, also don't forget to unblock port 80 on skype to allow the server to run

        – Timo Huovinen
        Feb 22 '17 at 11:06













        9














        I was getting the same error while trying to load simply HTML files that used JSON data to populate the page, so I used used node.js and express to solve the problem. If you do not have node installed, you need to install node first.




        1. Install express
          npm install express


        2. Create a server.js file in the root folder of your project, in my case one folder above the files I wanted to server



        3. Put something like the following in the server.js file and read about this on the express gihub site:



          var express = require('express');
          var app = express();
          var path = require('path');

          // __dirname will use the current path from where you run this file
          app.use(express.static(__dirname));
          app.use(express.static(path.join(__dirname, '/FOLDERTOHTMLFILESTOSERVER')));

          app.listen(8000);
          console.log('Listening on port 8000');


        4. After you've saved server.js, you can run the server using:



        node server.js




        1. Go to http://localhost:8000/FILENAME and you should see the HTML file you were trying to load






        share|improve this answer






























          9














          I was getting the same error while trying to load simply HTML files that used JSON data to populate the page, so I used used node.js and express to solve the problem. If you do not have node installed, you need to install node first.




          1. Install express
            npm install express


          2. Create a server.js file in the root folder of your project, in my case one folder above the files I wanted to server



          3. Put something like the following in the server.js file and read about this on the express gihub site:



            var express = require('express');
            var app = express();
            var path = require('path');

            // __dirname will use the current path from where you run this file
            app.use(express.static(__dirname));
            app.use(express.static(path.join(__dirname, '/FOLDERTOHTMLFILESTOSERVER')));

            app.listen(8000);
            console.log('Listening on port 8000');


          4. After you've saved server.js, you can run the server using:



          node server.js




          1. Go to http://localhost:8000/FILENAME and you should see the HTML file you were trying to load






          share|improve this answer




























            9












            9








            9







            I was getting the same error while trying to load simply HTML files that used JSON data to populate the page, so I used used node.js and express to solve the problem. If you do not have node installed, you need to install node first.




            1. Install express
              npm install express


            2. Create a server.js file in the root folder of your project, in my case one folder above the files I wanted to server



            3. Put something like the following in the server.js file and read about this on the express gihub site:



              var express = require('express');
              var app = express();
              var path = require('path');

              // __dirname will use the current path from where you run this file
              app.use(express.static(__dirname));
              app.use(express.static(path.join(__dirname, '/FOLDERTOHTMLFILESTOSERVER')));

              app.listen(8000);
              console.log('Listening on port 8000');


            4. After you've saved server.js, you can run the server using:



            node server.js




            1. Go to http://localhost:8000/FILENAME and you should see the HTML file you were trying to load






            share|improve this answer















            I was getting the same error while trying to load simply HTML files that used JSON data to populate the page, so I used used node.js and express to solve the problem. If you do not have node installed, you need to install node first.




            1. Install express
              npm install express


            2. Create a server.js file in the root folder of your project, in my case one folder above the files I wanted to server



            3. Put something like the following in the server.js file and read about this on the express gihub site:



              var express = require('express');
              var app = express();
              var path = require('path');

              // __dirname will use the current path from where you run this file
              app.use(express.static(__dirname));
              app.use(express.static(path.join(__dirname, '/FOLDERTOHTMLFILESTOSERVER')));

              app.listen(8000);
              console.log('Listening on port 8000');


            4. After you've saved server.js, you can run the server using:



            node server.js




            1. Go to http://localhost:8000/FILENAME and you should see the HTML file you were trying to load







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 14 '17 at 16:18









            patridge

            20.9k1576116




            20.9k1576116










            answered Nov 10 '14 at 14:10









            thehmethehme

            96511320




            96511320























                2














                If you have nodejs installed, you can download and install the server using command line:



                npm install -g http-server


                Change directories to the directory where you want to serve files from:



                $ cd ~/projects/angular/current_project 


                Run the server:



                $ http-server 


                which will produce the message Starting up http-server, serving on:



                Available on:
                http://your_ip:8080 and
                http://127.0.0.1:8080



                That allows you to use urls in your browser like




                http://your_ip:8080/index.html







                share|improve this answer




























                  2














                  If you have nodejs installed, you can download and install the server using command line:



                  npm install -g http-server


                  Change directories to the directory where you want to serve files from:



                  $ cd ~/projects/angular/current_project 


                  Run the server:



                  $ http-server 


                  which will produce the message Starting up http-server, serving on:



                  Available on:
                  http://your_ip:8080 and
                  http://127.0.0.1:8080



                  That allows you to use urls in your browser like




                  http://your_ip:8080/index.html







                  share|improve this answer


























                    2












                    2








                    2







                    If you have nodejs installed, you can download and install the server using command line:



                    npm install -g http-server


                    Change directories to the directory where you want to serve files from:



                    $ cd ~/projects/angular/current_project 


                    Run the server:



                    $ http-server 


                    which will produce the message Starting up http-server, serving on:



                    Available on:
                    http://your_ip:8080 and
                    http://127.0.0.1:8080



                    That allows you to use urls in your browser like




                    http://your_ip:8080/index.html







                    share|improve this answer













                    If you have nodejs installed, you can download and install the server using command line:



                    npm install -g http-server


                    Change directories to the directory where you want to serve files from:



                    $ cd ~/projects/angular/current_project 


                    Run the server:



                    $ http-server 


                    which will produce the message Starting up http-server, serving on:



                    Available on:
                    http://your_ip:8080 and
                    http://127.0.0.1:8080



                    That allows you to use urls in your browser like




                    http://your_ip:8080/index.html








                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Oct 6 '16 at 3:53









                    Rahul ReddyRahul Reddy

                    565614




                    565614























                        1














                        It works best this way. Make sure that both files are on the server. When calling the html page, make use of the web address like: http:://localhost/myhtmlfile.html, and not, C::///users/myhtmlfile.html. Make usre as well that the url passed to the json is a web address as denoted below:



                        $(function(){
                        $('#typeahead').typeahead({
                        source: function(query, process){
                        $.ajax({
                        url: 'http://localhost:2222/bootstrap/source.php',
                        type: 'POST',
                        data: 'query=' +query,
                        dataType: 'JSON',
                        async: true,
                        success: function(data){
                        process(data);
                        }
                        });
                        }
                        });
                        });





                        share|improve this answer




























                          1














                          It works best this way. Make sure that both files are on the server. When calling the html page, make use of the web address like: http:://localhost/myhtmlfile.html, and not, C::///users/myhtmlfile.html. Make usre as well that the url passed to the json is a web address as denoted below:



                          $(function(){
                          $('#typeahead').typeahead({
                          source: function(query, process){
                          $.ajax({
                          url: 'http://localhost:2222/bootstrap/source.php',
                          type: 'POST',
                          data: 'query=' +query,
                          dataType: 'JSON',
                          async: true,
                          success: function(data){
                          process(data);
                          }
                          });
                          }
                          });
                          });





                          share|improve this answer


























                            1












                            1








                            1







                            It works best this way. Make sure that both files are on the server. When calling the html page, make use of the web address like: http:://localhost/myhtmlfile.html, and not, C::///users/myhtmlfile.html. Make usre as well that the url passed to the json is a web address as denoted below:



                            $(function(){
                            $('#typeahead').typeahead({
                            source: function(query, process){
                            $.ajax({
                            url: 'http://localhost:2222/bootstrap/source.php',
                            type: 'POST',
                            data: 'query=' +query,
                            dataType: 'JSON',
                            async: true,
                            success: function(data){
                            process(data);
                            }
                            });
                            }
                            });
                            });





                            share|improve this answer













                            It works best this way. Make sure that both files are on the server. When calling the html page, make use of the web address like: http:://localhost/myhtmlfile.html, and not, C::///users/myhtmlfile.html. Make usre as well that the url passed to the json is a web address as denoted below:



                            $(function(){
                            $('#typeahead').typeahead({
                            source: function(query, process){
                            $.ajax({
                            url: 'http://localhost:2222/bootstrap/source.php',
                            type: 'POST',
                            data: 'query=' +query,
                            dataType: 'JSON',
                            async: true,
                            success: function(data){
                            process(data);
                            }
                            });
                            }
                            });
                            });






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 4 '16 at 19:04









                            kehindekehinde

                            96032350




                            96032350






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8449716%2fcross-origin-requests-are-only-supported-for-http-but-its-not-cross-domain%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Guess what letter conforming each word

                                Port of Spain

                                Run scheduled task as local user group (not BUILTIN)