jQuery加载问题相同的源策略 [英] jQuery load problems same origin policy
问题描述
我想从另一个站点加载内容(本质上是想检查页面上是否有内容).我知道同样的原产地政策会使这一点变得困难,但是我想知道是否有解决办法.我使用了以下方法: http://api.jquery.com/jQuery.getJSON/
I want to load in content from another site (essentially I want to check if something is on the page). I know the same origin policy makes this difficult, but I was wondering if there is a way around it. I looked into using this: http://api.jquery.com/jQuery.getJSON/
有没有更好,更简单的方法?看起来这仅适用于JSON.
Is there a better, simpler way? It looks like that is only for JSON.
谢谢
推荐答案
您可以使用
dataType: "jsonp"
但是我相信这要求您通过ajax加载的整个页面必须为JSON格式(可能不是).
but I believe this requires that the entire page you're loading via ajax be in JSON format (which it probably isn't).
我用来解决此问题的技术是使用服务器端脚本(例如PHP + CURL)来获取页面(或检查所需信息),然后在我的设备上使用jQuery ajax调用服务器端脚本(不是跨域脚本)来获取我想要的数据.
The technique I've used to get around this would be to use a server-side script (like PHP + CURL) to get the page (or check for the information I want) and then use a jQuery ajax call on my server-side script (which is not cross-domain) to get the data I want.
这篇关于jQuery加载问题相同的源策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!