在JavaScript中跨越跨域的最佳方法 [英] Best method to get over cross domain in javascript

查看:234
本文介绍了在JavaScript中跨越跨域的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的本地主机:8111一个restlet应用程序运行。这个应用程序有一个ServerResource从我正在做的javascript api响应http请求。



这个Javascript api是在我的apache在localhost中运行的,我想做http请求到本地主机:8111,但我不能为跨域问题。



在json中的restlet响应,这种情况下最好的解决方案? / p>

谢谢!

解决方案

与其他任何情况一样。 p>


  • CORS如果你想要控制,并愿意牺牲一些跨浏览器支持。

  • JSON-P如果您只能生活GET请求,并且没有安全性,哪些网站可以触发请求。

  • 如果不需要最终服务器直接从客户


i have in my localhost:8111 a restlet app running. This app have a ServerResource that respond http requests from a javascript api that i'm doing.

This Javascript api is running in my apache in localhost, and i want to do http request to the localhost:8111, but i can't for the cross domain problem.

The restlet response in json, which solution is the best in this case?

Thanks!

解决方案

The same as any other case.

  • CORS if you want control and are willing to sacrifice some cross-browser support.
  • JSON-P if you can live with GET only requests and no security over which sites can trigger the request
  • A proxy on the same origin if you don't need the final server to get credentials directly from the client

这篇关于在JavaScript中跨越跨域的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆