So I have the below code:
var formData = new FormData();
formData.append("title", document.getElementById("title").value);
formData.append("html",my_html);
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://www.mywebsite.com/index");
xhr.send(formData);
xhr.onreadystatechange = function() {
// If the request completed, close the extension popup
if (req.readyState == 4)
if (req.status == 200) window.close();
};
The server is supposed to send back a response in JSON format.
How do I retrieve and store that in a variable?
If the answer is in JSON, you have the result in the responseText attribute.
For more details, view: XMLHttpRequest