Given this HTML skeleton, write the necessary JavaScript code to make the page into a chat program.
Read and submit chat messages by making Ajax requests to the provided
(chatit.php) on Webster.
(sample solution)
GET request to ask the PHP script for all messages.
Optional parameters:
reverse returns output in reverse-chronological order;
limit returns only that many most recent posts
POST request to the PHP script with the parameter msg to submit a message.
(see next slide and/or Ajax POST slides)
POST request
var params = new FormData();
params.append("name", value);
params.append("name", value);
var ajax = new XMLHttpRequest();
ajax.onload = functionName;
ajax.open("POST", "url", true);
ajax.send(params);
FormData object to gather your POST query parametersFormData to the request's send methodmethod passed to open should be changed to "POST"You can view the solution JavaScript code here.