current position:Home>Ajax sends a post request

Ajax sends a post request

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

send out POST request

demand : When the mouse is placed in the frame , Send a request to the server , When it comes back , Present the response results in div in

 Insert picture description here
html Written in a file ajax Code , And run
 Insert picture description here

terms of settlement :

// stay js Newly added 
app.post('/server',(request,response)=>{
    
    // Set the response header .(' name ',' value ')  Set allow cross domain 
    response.setHeader('Access-Control-Allow-Origin','*');

    // Set the response body 
    response.send('HELLO AJAX POST');
});

Restart the service after the change :
Run discovery . Data appears when the mouse moves in
 Insert picture description here

POST Set request body

The request body can be in any format , As long as the server can handle . But it's best to write in a specific format .
such as :

  • a=1&b=2&c=3
  • a:1&b:2&c:3
  • ······

 Insert picture description 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/202204290810023139.html

Random recommended