AJAX

Step 4: To send a chat message to the server, use a technique called AJAX, which stands for Asynchronous JavaScript And XML. Add the following to your event listener function for the send button:
let request = new XMLHttpRequest()
request.open(`POST`, `/message`)
request.setRequestHeader(`Content-Type`, `application/json`)

let requestBody = {
  message: yourTextBoxVariable.value
}

request.send(JSON.stringify(requestBody))
A post request is sent to the route /message. The body of the request is in JSON format, which stands for JavaScript Object Notation, and is pronounced Jason. The body of the request contains a property called message, which is set to the text box value. Change yourTextBoxVariable to the name of your variable. You will verify that the request is sent in the next step.
Last step Next step