Solving this situation is quite simple: you just have to add headers to your response indicating what the browser is allowed to request and what not. So if the server response with some explanatory headers and a 200 OK response, the browser will send the GET request and your application will have the data it needs. This OPTIONS request is simply there for the browser to ask the server if it can request this data. > GET When the domain differs, the browser will send an OPTIONS request before it sends the GET request. > GET # A preflight request will be sent here, the domains are the different (localhost:4200, localhost:8000) This also applies when you request data on localhost but on a server running on a different port, example: # No preflight request will be sent here, the domains are the same (localhost:8000) But what does it mean and how do you solve it? What is a Preflight request?Ī preflight request is a simple request your browser automatically sends to the server when you're requesting data through an AJAX call in JavaScript when you're not requesting data from the same domain name. This request won't have the normal request type you're used to (GET, POST, PUT, DELETE), but it'll have type OPTIONS. Your browser will send an additional request to your server, a so called Preflight request. Making cross-domain XHR requests can be a pain when building a web application as a single page application, fully written in JavaScript. How to fix CORS headers in a single page application Home Blog How to fix CORS headers in a single page application
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |