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

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

问题描述

请求时(HT | X)毫升与阿贾克斯只能请求发送到同一个域。但是,如果你要求的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(响应)。既然你不运行的远程code直接更是你的控制之下,一切都很好大多是在世界。

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天全站免登陆