jQuery load problems same origin policy

浪子不回头ぞ 提交于 2020-01-16 18:01:09

问题


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/

Is there a better, simpler way? It looks like that is only for JSON.

Thanks


回答1:


You can use

dataType: "jsonp"

but I believe this requires that the entire page you're loading via ajax be in JSON format (which it probably isn't).

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.



来源:https://stackoverflow.com/questions/9027988/jquery-load-problems-same-origin-policy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!