简体   繁体   English

使用JQuery load / ajax从其他域加载DIV内容

[英]load DIV content from other domain using JQuery load/ajax

I have a requirement where I have to load a content in a DIV from a domain other than source domain. 我有一个要求,我必须从源域以外的域中加载DIV中的内容。

Eg: 例如:

$("#myDiv").load("https://www.google.com")

Now in above example, I want to load google page content into a DIV on my JSP. 现在在上面的示例中,我想将Google页面内容加载到我的JSP上的DIV中。

Now, the problem is request is blocked due to browser's same origin policy. 现在,问题是由于浏览器的相同来源策略,请求被阻止。

I have gone through some solutions to set headers at server. 我已经通过一些解决方案在服务器上设置标头。 But I am not suppose to alter headers in this case as this may affect other aspects of my application. 但是我不打算在这种情况下更改标题,因为这可能会影响应用程序的其他方面。

Also, solutions like YQL may not work as I am not suppose to make java script/ ajax call to other locations due to som security concerns. 另外,由于som的安全问题,像YQL这样的解决方案可能无法正常工作,因为我不认为可以将Java脚本/ ajax调用到其他位置。

I am currently looking for a library / api / workaround or any open source solution that can address my problem. 我目前正在寻找可以解决我的问题的library / api / workaround或任何开源解决方案。

PS: I am working with servlets and JSP PS:我正在使用servlets and JSP

Any suggestions/solution please. 任何建议/解决方案,请。

Thanks in advane. 谢谢。

If source domain is yours or you can change the return value then you can do jquery ajax call with the data type jsonp. 如果源域是您的,或者您可以更改返回值,则可以使用数据类型jsonp进行jquery ajax调用。 If you can't access the source domain then this is not possible because of security reasons. 如果您无法访问源域,则出于安全原因,这是不可能的。 As an another solution we can use small proxy which manage requests and responses, but again you should have rights to access the source domain. 作为另一个解决方案,我们可以使用小型代理来管理请求和响应,但是同样,您应该有权访问源域。

look at this, 看这个, 在此处输入图片说明

proxy can comunicate with the server 2 without any restrictions since which are in the same domain. 代理可以与服务器2通信,而没有任何限制,因为它们在同一域中。 And you can implement proper interface in proxy which allow to communicate with external servers or clients like server1. 并且您可以在代理中实现适当的接口,该接口允许与外部服务器或客户端(例如server1)进行通信。 Using this model you don't need to change server 2. 使用此模型,您无需更改服务器2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM