View Full Version : Ajax Includes Script from another server domain

05-01-2011, 09:44 AM
1) Script Title:
Ajax Includes Script
2) Script URL (on DD):
3) Describe problem:
how can i use this ajax script for an external domain (another server file).

05-01-2011, 02:15 PM
I think the most likely exactly what you want is banned/forbidden for safety/security reasons.


05-01-2011, 04:09 PM
Browsers block this. I'm not sure if it's theoretically allowed for Ajax or not, but regardless it won't work in any (major) browser.

You will need to find an alternative such as using an iframe or getting the content indirectly through a serverside language like PHP and using Ajax to load that page.

05-05-2011, 04:49 AM
ok, how can i do this with php or other but i don't want to use iframe

05-05-2011, 05:20 AM
You will create a PHP file on your website that acts as a proxy to take the information from the external site and display it on your own.
You should start with gaining a general understanding of how PHP works. Then you can probably find a lot of information in tutorials for various ways to do this. Note that PHP may be configured to disallow including external files (similar to what Ajax does) but this can be overridden as long as you have access to the server settings. In many cases it is not a problem, but it's worth mentioning because it can be confusing otherwise.

The easiest approach will be the following:


But you might want to use a variable filename if you plan to reuse this for several possible URLs. You could do this using a get variable sent in the URL of the PHP page such as mypage.php?page=http://url.../

The exact requirements of your system may vary, but that should get you started. Once you have made some progress, let us know about any specific questions.

After the external page has been brought to your website by PHP, you will use that page with the Ajax script like you were originally trying to do and you will have no problems because that content is actually now on your website (indirectly).

Please be aware of copyright and TOS when taking content from other websites.

05-05-2011, 05:57 AM
HTML5 has an API -messaging (http://www.google.com/search?ie=UTF-8&q=html5+messaging)- that allows javascript to work across domains. Both domains have to cooperate to use it - and that may or may not defeat your purpose.

05-05-2011, 07:56 AM
djr33 thanks for your reply
i don't what to copy other site contents , i have 2 website which is my own (hosting and domain) i want to display my other website webpage to dispaly in my main webiste. that why i asking for this. and bro i have no to much knowledge about php. if you can help me about this , i will very thankfull to you.

05-05-2011, 04:28 PM
If you own both websites, then traq's suggestion can help.

Otherwise, unfortunately unless you want to hire a web designer, you will have to become familiar with PHP. There is no single best "answer" to your question-- there are a lot of ways to do this, and in order to find the right one for your website you will need to learn about them.
Using the code I posted above you can bring in the contents of an external site.

Here is a VERY basic tutorial to get started:
Create a new page called "something.php" (Any name you want, but it must end in php) and add the following contents to it:

Save the page and load it in your browser. That will load google's search page into your site. (This is JUST an example. Replace the URL with anything you'd like.)

If nothing goes wrong (and it probably won't), then that will work. (It requires that you have PHP installed/enabled on your server and that including external files is allowed in your configuration.)

If you don't want to learn PHP, you can create a new PHP page just like that for every external page you will use. You could also use PHP to make it more powerful such as loading a page requested by Ajax. But that requires learning PHP.