Home  >  Article  >  Web Front-end  >  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
Mary-Kate OlsenOriginal
2024-11-07 20:56:031036browse

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

On Linux:

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

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

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!

Statement:
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