ajax - 使用JSON解决跨域问题

标签 ajax

基于 JavaScript 的 AJAX 似乎是一个好方法,直到我们遇到 AJAX 客户端只能从下载位置与服务器通信的限制,从而遵守“同源策略”。

有人可以告诉我 JSON 如何解决这个跨域问题吗?据我所知,JSON 只是一种数据格式,说明如何呈现数据。

请您对此提出建议 我的问题是如何通过不同结构的数据格式来控制 XMLHttprequest

最佳答案

参见JSONP在维基百科上:

JSONP or "JSON with padding" is a complement to the base JSON data format, a pattern of usage allowing a page to request data from a server in a different domain. JSONP is a solution to this problem, forming an alternative to a more recent method called Cross-Origin Resource Sharing.

...

The server then wraps its JSON response with this prefix, or "padding", before sending it to the browser. When the browser receives the wrapped response from the server it is now a script, rather than simply a data declaration.

关于ajax - 使用JSON解决跨域问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7173044/

相关文章:

javascript - JQuery/AJAX Toggle 将 POST 切换到 php 文件,无需导航

javascript - 使用ajax加载jquery htmlbox

php - 为 WooCommerce 中的特定结账字段启用更新结账

javascript - 如何使用ajax填充javaScript数组

javascript - 检测 ajax 成功函数何时需要超过 5 秒并重定向

javascript - 从 XML 文件中分离出一个结果

javascript - jQuery/Ajax - 尝试通过 Ajax 创建 POST 方法并获取对 HTML 的响应

javascript - 使用 ajax 的表单 - 消息表单 php,无需刷新页面

javascript - iOS 6 上的 Safari 是否缓存 $.ajax 结果?

JavaScript/Ajax NTLM 身份验证