简体   繁体   中英

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.

Eg:

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

Now in above example, I want to load google page content into a DIV on my JSP.

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.

I am currently looking for a library / api / workaround or any open source solution that can address my problem.

PS: I am working with 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. 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. And you can implement proper interface in proxy which allow to communicate with external servers or clients like server1. Using this model you don't need to change server 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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