Search code examples
javascriptrestpostmessage

How do I use postMessage() in Javascript?


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?


Solution

  • This 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.