基于 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/