Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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?

like image 856
siannone Avatar asked Dec 09 '11 17:12

siannone


People also ask

How do I fix cross-origin requests are only supported for protocol schemes?

Just change the url to http://localhost instead of localhost . If you open the html file from local, you should create a local server to serve that html file, the simplest way is using Web Server for Chrome . That will fix the issue.

Does CORS work with https?

CORS requests may only use the HTTP or HTTPS URL scheme, but the URL specified by the request is of a different type. This often occurs if the URL specifies a local file, using the file:/// scheme.

What is cross-origin request in web api?

A cross-origin HTTP request is one that is made to: A different domain (for example, from example.com to amazondomains.com ) A different subdomain (for example, from example.com to petstore.example.com ) A different port (for example, from example.com to example.com:10777 )

How does a CORS request work?

Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served. A web page may freely embed cross-origin images, stylesheets, scripts, iframes, and videos.


1 Answers

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:\ ... \Application\chrome.exe --allow-file-access-from-files 

to the end of the "target" path

like image 169
prauchfuss Avatar answered Sep 28 '22 19:09

prauchfuss