Home > Article > Web Front-end > Why Does My Same-Origin AJAX Request Fail with a 'Cross Origin Request Error'?
Cross Origin Request Error: File Fetch Fails for Same-Origin Request
When attempting to make an AJAX request to a local webserver file using jQuery, developers may encounter the following error: "XMLHttpRequest cannot load file:///C:/xampp/htdocs/webname/resources/templates/signup.php. Cross origin requests are only supported for HTTP."
Despite the error message suggesting a cross-domain request issue, in this case, the request is for a local file hosted on the same web server as the website.
Solution: Allow File Access via Chrome Switch
To resolve this problem, developers can utilize a Chrome command-line switch to allow file access from local files.
For OS X:
open -a 'Google Chrome' --args -allow-file-access-from-files
For *NIX:
google-chrome --allow-file-access-from-files
For Windows:
Edit the target path of the Chrome shortcut, adding the following switch:
C:\ ... \Application\chrome.exe --allow-file-access-from-files
The above is the detailed content of Why Does My Same-Origin AJAX Request Fail with a 'Cross Origin Request Error'?. For more information, please follow other related articles on the PHP Chinese website!