current position:Home>Ajax notes

Ajax notes

2022-04-29 08:10:14Chen Chen is trying

Set request header

// Set request header 
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//Content-Type: Set the content type of the request body 
//application/x-www-form-urlencoded: Fixed writing method of parameter query string 

You can also set other header information
for example :

xhr.setRequestHeader('name','cxjcxj');// Self defined 

The browser will report an error :
 Insert picture description here
What if you don't want him to make a mistake ?
answer :
step1:

// Response head 
response.setHeader('Access-Control-Allow-Header','*');// All types of header messages can be received 

 Insert picture description here
Not yet , Because he will send a message OPTIONS request
 Insert picture description here
This request will do a new verification , That is, send a request to detect whether the header information is available or not
So next :
step2:
 Insert picture description here

all It means : Can receive any type of request , all http Request for agreement , It can be received here
After operation :
 Insert picture description here

copyright notice
author[Chen Chen is trying],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/04/202204290810099771.html

Random recommended