所以我有下面的代碼:檢索Post Request響應並存儲到變量中?
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();
};
服務器應該發回一個JSON格式的響應。 如何檢索並將其存儲在變量中? 任何人都可以幫忙嗎?