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.
if (xhr.readyState == 4)
if (xhr.status == 200)
var json_data = xhr.responseText;
For more details, view: XMLHttpRequest
Just use xhr.responseText
to get the response of the request. You can also use xhr.responseXML
to retreive a DOM-compatible document object of the response, that means you can access it like document
.
Source: http://developer.apple.com/internet/webcontent/xmlhttpreq.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With