Results 1 to 3 of 3

Thread: AJAX Client-side Get Code Of Another Site

  1. #1
    Join Date
    Oct 2010
    Thanked 0 Times in 0 Posts

    Default AJAX Client-side Get Code Of Another Site


    Is it possible to create a client-side script to get code of another website, similar to PHP get_file_contents but from client-side not server side?

    If so can you please tell me how or provide some code to use ajax to return the code of another website into a variable please.

    Any help would be greatly appreciated.

  2. #2
    Join Date
    Mar 2005
    Thanked 3,267 Times in 3,228 Posts
    Blog Entries


    It isn't possible. Client side (browser) security restrictions will not allow it.
    - John

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2006
    Illinois, USA
    Thanked 690 Times in 678 Posts


    As John said, it's intentionally blocked. (It's theoretically possible and there's no reason that it won't work except that browsers block it.)
    There are two possible ways around this. However, in most cases this is a problem anyway, since you may not have permission from the external site. In some cases (if you own both, for example) it may be fine, so I will post the workarounds anyway.

    1. I believe that there is some way to create a document that allows this in your server: crossdomain.xml. It may not work in all cases, and you might need the same file on both servers. The intent of that is to allow this sort of thing if you have permission. I don't know any more information about this and the one time I tried it I didn't get it to work-- then I find another approach and didn't need to do it any more. Try google or maybe someone here will know more than I do.

    2. Since you are already using PHP, you could easily get around this by doing an Ajax request to a PHP page on your server that uses file_get_contents() to grab the external website. There may be problems with this, such as if the website doesn't respond quickly or if there is a typo (or intentional bad request) from Javascript. Verify the URL first if you can.
    This should work in all cases. But still be careful and think about whether this is really the right approach to solving your problem.
    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


Posting Permissions

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