Results 1 to 8 of 8

Thread: Ajax Includes Script from another server domain

  1. #1
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ajax Includes Script from another server domain

    1) Script Title:
    Ajax Includes Script
    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...axincludes.htm
    3) Describe problem:
    how can i use this ajax script for an external domain (another server file).

  2. #2
    Join Date
    Jan 2011
    Posts
    51
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default

    Hi!
    I think the most likely exactly what you want is banned/forbidden for safety/security reasons.

    Luys

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok, how can i do this with php or other but i don't want to use iframe

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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:
    PHP Code:
    <?php
    include('http://the.external.site/path/to/file.ext');
    ?>
    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    HTML5 has an API -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.

  7. The Following User Says Thank You to traq For This Useful Post:

    djr33 (05-05-2011)

  8. #7
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  9. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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:
    PHP Code:
    <?php
    include('http://www.google.com/index.html');
    ?>
    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •