简体   繁体   中英

How do I do cross-domain http requests in Javascript?

So I'm developing a Sencha (Javascript) app which needs to make Ajax http requests to a REST service that is already in place on a different domain. I need a solution to be able to make POST, PUT, and GET requests from my Sencha javascript to that service. I have no control over the service so I cannot make any changes on that end. I have heard of HTML5's new postMessage() method, but I am unsure how to use or if I am even able to use it to do what i want. Of course, I could disable browser security while in development but that is not a permanent solution. Any suggestions?

In particular, if someone could inform me of the use(s) of the postMessage method, I would be most grateful.

If the response is JSON, you can use JSONP . If you are posting, use a hidden Iframe.

您可以使用serverSide Proxy(PHP,servlet ....)来调度您的跨域请求,拉出响应,然后将结果返回给客户端的javascript。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM