After clicking the submit button a sendJSON() is called which is defined below.
When sending data to a web server, the data has to be a string. So we are using JSON.stringify() function to convert data to string and send it via XHR request to the server. Below is the sample code.
We are using PHP as a scripting language. Create a file named submit.php, in this file, we’ll decode the received data to JSON and return a sentence formed using the received data.
Now when you fill the details and press the Send JSON button you’ll see something like: