没有JSONP的JSON跨站点 [英] JSON cross site without JSONP

查看:77
本文介绍了没有JSONP的JSON跨站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地硬件,可以通过其IP地址访问该硬件以检索json数据.

I have a local piece of hardware that I access via it's IP address to retrieve json data.

我正在创建一个基于Web的应用程序,但是由于跨域问题,当该应用程序在网络上运行时,它无法访问本地json数据.

I am creating a web based app but it can not access the local json data when the app is running on the web due to cross domain issues.

是否有合适的解决方案可将JSON数据提供给网络应用?

Is there a suitable solution to make the JSON data available to the web app?

我正在使用jQuery在本地读取JSON文件.

I'm using jQuery to read the JSON file locally.

该硬件当前不提供JSONP.

The hardware currently doesn't provide JSONP.

谢谢.

推荐答案

您可以使用PHP/ASP/etc代理它.您的本地站点上的页面(在后端)将查询远程信息.这样,您就可以调用somesite.com/getForeignData(实际上是调用othersite.com/foreignData)并在同一域中将其返回.

You can proxy it with a PHP/ASP/etc. page on your local site that (in the back-end) will query the remote information. This will allow you to call somesite.com/getForeignData (which actually calls othersite.com/foreignData) and return it within the same domain.

除此之外,您将需要使用JSONP(这是故意设置的边界). 最后一个"选项是在您的浏览器上启用跨边界调用,但是如果您希望其他人具有相同的功能,这只是一个临时解决方案.

Other than that, you're going to need to use JSONP (this is a boundary purposely set). The "last" option is to enable cross-boundary calls on your browser, but if you want others to have the same ability, this is only a temporary solution.

这篇关于没有JSONP的JSON跨站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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