Home >Web Front-end >JS Tutorial >How to Resolve \'XMLHttpRequest cannot load\' CORS Error with Unsupported Protocol Schemes?

How to Resolve \'XMLHttpRequest cannot load\' CORS Error with Unsupported Protocol Schemes?

Barbara Streisand
Barbara StreisandOriginal
2024-12-01 10:01:131031browse

How to Resolve

CORS Error: "Requests are Only Supported for Protocol Schemes: http..."

The "XMLHttpRequest cannot load" error occurs when cross-origin requests are attempted without the proper protocol schemes. In this case, the Angular Service is trying to access the JSON string from the Express backend at localhost:4201/ticker, but is encountering a CORS error.

To resolve this issue, the protocol scheme must be explicitly included in the request URL in the Angular Service. The error message indicates that only http, data, chrome, chrome-extension, and https schemes are supported. Therefore, the URL should be modified to include http:// before localhost:

this._baseUrl = 'http://localhost:4201/';

With this adjustment, the Angular Service can now make cross-origin requests using the http scheme, addressing the CORS error and allowing the JSON string to be retrieved successfully.

The above is the detailed content of How to Resolve \'XMLHttpRequest cannot load\' CORS Error with Unsupported Protocol Schemes?. 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