Ajax - JSON的跨域限制 [英] Cross Domain Limitations With Ajax - JSON

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

问题描述

当使用ajax请求(ht | x)ml时,您只能向同一个域发送请求。但如果您请求JSON,您可以将其发送到任何域。为什么?

When requesting (ht|x)ml with ajax you can only send requests to the same domain. But if you request JSON you can send it to any domain. Why?

我被告知这是为了安全,但为什么一个网站通过ajax做恶意的,而不是直接的,如果这是有意义的。

I'm told it's for security but why would a website do something malicious via ajax rather than just directly if that makes sense.

推荐答案

请查看此维基百科文章

JSON是安全的的原因是因为你必须通过回调传递它。远程站点将运行返回JSON,你的javascript库不会盲目运行,但尝试将其传递给您指定的函数,如 jsonpCallback(response)。由于你不是直接运行远程代码,更多的是在你的控制下,一切都在世界上很好。

The reason why JSON is 'safe' is because you have to pass it through a callback. The remote site will run return JSON and your javascript library will not just run it blindly but try to pass it to a function you specify, like jsonpCallback( response ). Since you aren't running the remote code directly much more is under your control and all is mostly well in the world.

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

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