Home > Web Front-end > JS Tutorial > Why Am I Getting a 'Cross origin requests are only supported for HTTP' Error Despite Same-Origin Hosting?

Why Am I Getting a 'Cross origin requests are only supported for HTTP' Error Despite Same-Origin Hosting?

Mary-Kate Olsen
Release: 2024-11-07 20:56:03
Original
1061 people have browsed it

Why Am I Getting a

Cross-Origin Requests Error Despite Same-Origin Hosting

When attempting to make an AJAX request using the provided code, you may encounter the error "Cross origin requests are only supported for HTTP" despite the fact that the target file, "signup.php," is hosted on the same web server. This error typically arises when making requests across different domains, but in this case, it is not a cross-domain issue.

Solution:

To resolve this issue, you can enable file access from local files by starting Google Chrome with a specific switch.

On macOS:

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

On Linux:

google-chrome --allow-file-access-from-files
Copy after login

On Windows:

Edit the properties of the Chrome shortcut and add the switch to the end of the "target" path:

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

By enabling file access, you grant Chrome permission to access local files, including those hosted on the same server as your website. This resolves the error and allows your AJAX request to load the requested file.

The above is the detailed content of Why Am I Getting a 'Cross origin requests are only supported for HTTP' Error Despite Same-Origin Hosting?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template