简体   繁体   English

不使用代理的跨域POST Ajax请求

[英]Cross-domain POST Ajax request without using proxy

Is it even possible to perform a cross-domain POST Ajax request without using proxy? 甚至可以在不使用代理的情况下执行跨域POST Ajax请求? I'm willing to use any kind of library to do this. 我愿意使用任何一种库来做到这一点。

PS Request response is in JSON format. PS请求响应为JSON格式。

There is no way to do it if you don't control the server. 如果您不控制服务器,则无法执行此操作。 Server side proxy is your only option. 服务器端代理是您唯一的选择。

Good thing is server-side proxy is fairly easy to do. 好东西是服务器端代理相当容易做到。 Just create an endpoint that accepts the details of the request you want to make (http method, url, params), and then use whatever URL mechanism your framework of choice has to hit the other domain. 只需创建一个接受您要发出的请求的详细信息的终结点(http方法,url,params),然后使用您选择的框架必须使用的其他URL机制才能打入另一个域。

The other possibility is to use JSONP , which uses a script tag instead of AJAX 另一种可能性是使用JSONP ,它使用脚本标记而不是AJAX

However, that requires that the server already support it, since it needs to wrap the returned JSON 但是,这需要服务器已经支持它,因为它需要包装返回的JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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