是否可以从 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);
我想在屏幕上打印。可能吗?
最佳答案
是的,只要相关域接受请求,并且服务器允许 CORS(跨源资源共享),就可以向任何域发出请求。仅当您想要响应时才需要后者,因为您正在跨源共享资源。
关于javascript - 我可以将以下代码发布到任何其他域吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55216553/