Unless your external content is served from the same domain as your main web site, using AJAX for something like this is not that easy, because you'd bump into the same origin policy.
One solution to work around the same origin policy would be to set up a simple reverse proxy on the server, which will allow the browser to use relative paths for the AJAX requests, while the server would be acting as a proxy to any remote location.
If using mod_proxy in Apache, the fundamental configuration directive to set up a reverse proxy is the ProxyPass
. It is typically used as follows:
ProxyPass /external/ http://other-domain.com/
In this case, the browser would be able to request /external/index.html
as a relative URL, but the server would serve this by acting as a proxy to http://other-domain.com/index.html
.
Then in your JavaScript, you would be able to use the jQuery load()
method as follows:
$('#your_div').load('external/index.html');
Another option is to use an iframe, and adjust its height dynamically with JavaScript. You may want to check the following Stack Overflow posts for further reading on this topic:
You may also want to consider a full server-side solution as @Yi Jiang suggested in a comment above. You could inject the HTML from the external site into your main site before serving it to the client's browser.