Sounds like you're talking about "cross-domain scripting" which as
Richard mentioned, isn't possible with AJAX requests - the
jquery .load() command uses AJAX, so what Richard is saying is it's
simply not possible to use jQuery's .load() to access an html file on
a different domain. With AJAX, the file you access must be on the same
domain as the page that's trying to access it - that security
restriction is built into all modern web browsers.

There's another way to load information dynamically (not using AJAX)
from files hosted on other domains as long as they are javascript
code, but it sounds like you want something that can access files
containing html code.

The type of request you are are asking about is usually handled using
a server-side programming language. With server-side languages like
PHP or Perl etc you can easily make an HTTP request to any page on any
domain & store/process the result.

With PHP I believe you'd use Curl:
http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl
http://us2.php.net/manual/en/ref.curl.php

With Perl you'd use LWP:
http://www.perl.com/pub/a/2002/08/20/perlandlwp.html

One way to accomplish your request is to make a server-side proxy
script. Basically here's how that works - your web page makes an AJAX
request to the proxy script, which in turn makes the cross-domain HTTP
request, & then returns the result to your page via AJAX. AJAX works
for this because the proxy script is on the same server as your web
page. Keep in mind there are security implications about making a
proxy that accesses any page on any other domain - you'd probably want
to come up with a method so that your proxy script can only be
accessed by your web page. Here's an article about that method:
http://fleegix.org/articles/2005/11/07/cross-domain-ajax-requests

Hope that helps!
-Wick


On Nov 8, 9:59 am, caruso_g <[EMAIL PROTECTED]> wrote:
> Ciao Richard,
> thanks a lot, really.
>
> It, clearly, works.
>
> But, if I may ask you more, if I would to pass an address with the
> same problem to a jQuery selector, what should I write?
> Would it enough to create a variable and insert its name into the
> selector?
> Below it is an example:
>
>     var my_variable_name = '"' + document.location.hostname + '/folder/
> subfolder/file.html';
>
>     jQuery(my_variable_name).something;
>
> Would it be right? That is just to learn.
> Thanks anyway again for your help.
>
> On Nov 8, 3:02 pm, "Richard D. Worth" <[EMAIL PROTECTED]> wrote:
>
> > No need to provide the full URL, including the domain/server name. In fact,
> > there's a security restriction on Ajax that prevents fetching an html page
> > from a domain other than the current one, so you only need to specify a
> > relative url to load:
>
> > jQuery('#footer-navbar').load("/clients/clickadvisor-02/snippets/footer-
> > navbar.html");
>
> > - Richard
>
> > On Nov 8, 2007 6:04 AM, caruso_g <[EMAIL PROTECTED]> wrote:
>
> > > I should have made progresses, I hope.
>
> > > I saw that it would be better to use .load method to get some simple
> > > pre-formatted html bunch of code.
>
> > > But the problem is still there, I don't know how to pass as arguments
> > > a domain address I am not able to know in advance.
> > > So I tried with the code below, but it doesn't work:
>
> > >        function address() {
> > >                var website = document.location.hostname;
> > >                var snippet_address = '"' + website +
> > > '/clients/clickadvisor-02/
> > > snippets/footer-navbar.html"';
> > >                document.write(snippet_address);
> > >        }
>
> > >        jQuery('#footer-navbar').load("address();");
>
> > > Any suggestion?
>
> > > On Nov 7, 10:45 pm, caruso_g <[EMAIL PROTECTED]> wrote:
> > > > First of all I want to apologize with all devs out there for my
> > > > questions. I am sure that solution will be easy but I am just a
> > > > designer, so I am a moron with Javascript...
>
> > > > The problem is that I need to put some html code into a div (#footer-
> > > > navbar) getting the html code from a page of which I already know its
> > > > hierarchy (clients/clickadvisor-02/snippets/footer-navbar.html) but of
> > > > which I don't know its domain (http://www.I_DONT_KNOW_THIS.COM).
> > > > I tried to create a script with jQuery like this:
>
> > > > jQuery('#footer-navbar').html(function () {
> > > >   jQuery.get(function () {
> > > >     document.write('"' + this.location.hostname + 'clients/
> > > > clickadvisor-02/snippets/footer-navbar.html"')
> > > >     });
>
> > > > });
>
> > > > Where do I make a mistake?
>
> > > > Thanks in advance to everyone.
>
> > > > ps
> > > > I am making use of "jQuery" because of some incompatibilities with
> > > > other libraries.

Reply via email to