Home > Web Front-end > JS Tutorial > Why Does My Same-Origin AJAX Request Fail with a 'Cross Origin Request Error'?

Why Does My Same-Origin AJAX Request Fail with a 'Cross Origin Request Error'?

DDD
Release: 2024-11-06 06:06:02
Original
284 people have browsed it

Why Does My Same-Origin AJAX Request Fail with a

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.

  1. For OS X:

     open -a 'Google Chrome' --args -allow-file-access-from-files
    Copy after login
  2. For *NIX:

    google-chrome --allow-file-access-from-files
    Copy after login
  3. For Windows:
    Edit the target path of the Chrome shortcut, adding the following switch:

    C:\ ... \Application\chrome.exe --allow-file-access-from-files
    Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template