admin管理员组文章数量:1391981
Is it possible to use the postMessage()
method in Javascript to do cross-domain POST
, GET
, PUT
, etc. calls? If so, how? And how do I pass headers and data?
Is it possible to use the postMessage()
method in Javascript to do cross-domain POST
, GET
, PUT
, etc. calls? If so, how? And how do I pass headers and data?
2 Answers
Reset to default 3This is a two way implementation, meaning that the page you want to call needs to have a callback that listens to such a message and give an appropriate response. You can't simply use it as a swap replacement for AJAX. The best method for that is to use a server-side proxy.
See this page for an explanation of how postMessage
works.
Yes, it is possible.
There is a nice demo of what exactly you want, here
document.getElementById("iframe").contentWindow.postMessage(
document.getElementById("message").value,
"http://anotherdomain."
);
handled on the second side with
window.onmessage = function(e){
if ( e.origin !== "http://html5demos." ) {
return;
}
document.getElementById("test").innerHTML = e.origin + " said: " + e.data;
};
本文标签: restHow do I use postMessage() in JavascriptStack Overflow
版权声明:本文标题:rest - How do I use postMessage() in Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744680036a2619346.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论