【发布时间】:2019-08-08 12:53:48
【问题描述】:
是否可以从 JavaScript 向任何服务器发出 HTTP POST 请求 域名?
Javascript
var xhr = new XMLHttpRequest();
xhr.open("POST", 'URL linki', true);
//Send the proper header information along with the request
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
// Request finished. Do processing here.
}
}
xhr.send("foo=bar&lorem=ipsum");
// xhr.send(new Int8Array());
// xhr.send(document);
我想在屏幕上打印。有可能吗?
【问题讨论】:
-
是的,只要 a) 它接受它,b) 它理解它,并且 c) 如果你想要一个响应,服务器允许 CORS
-
你可以,但你可能不会:)
-
为什么我不能,你能解释一下吗
-
你需要的都在这里:ajax-cross-origin.com/how.html
-
tnx 这么多,我很好理解:)
标签: javascript ajax cors xmlhttprequest same-origin-policy