Home >Web Front-end >JS Tutorial >How to Fix \'XMLHttpRequest cannot load...requests are only supported for protocols: http, data...\' CORS Errors in Angular and Express?
CORS Error: "XMLHttpRequest cannot load...requests are only supported for protocols: http, data..."
Problem:
When attempting to access a JSON string via Angular Service from an Express backend, users may encounter the following CORS error: "XMLHttpRequest cannot load localhost:4201/ticker. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https."
Answer:
This error occurs when using an incorrect URL protocol in the request. To resolve it, ensure the protocol is explicitly specified in the URL.
In this specific case, the solution is to add "http://" before the localhost address in the Express backend, as follows:
this._baseUrl = 'http://localhost:4201/';
This ensures that the correct URL format is used to fulfill the request and resolve the CORS error.
The above is the detailed content of How to Fix \'XMLHttpRequest cannot load...requests are only supported for protocols: http, data...\' CORS Errors in Angular and Express?. For more information, please follow other related articles on the PHP Chinese website!