admin管理员组文章数量:1208155
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", "");
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?
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?
Share Improve this question edited Aug 22, 2018 at 16:51 beaver 5271 gold badge9 silver badges21 bronze badges asked Oct 6, 2011 at 12:17 MaxMax 4,4086 gold badges40 silver badges57 bronze badges3 Answers
Reset to default 12If 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
Your response is in xhr.responseText
.
Check this: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
本文标签: javascriptRetrieving the Post Request response and storing into a variableStack Overflow
版权声明:本文标题:javascript - Retrieving the Post Request response and storing into a variable? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738721557a2108776.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论