Right, a dynamic <script> element is the only browser-based way around the
cross-domain restriction. You can load a script from any domain, but you
can't use that ability to read an HTML page.

So for your purposes it has to be something you run on your server.

I would suggest not proxying the entire page from the other site. Instead,
write code on your server that looks at the HTML page and creates a small
JSON object with the specific info you need. Then have your JavaScript code
do a $.getJSON() on that object.

If you don't need real-time status of this target page, you can fetch it
periodically from your server and store the latest JSON object. Or you can
fetch it every time.

-Mike

On Wed, Sep 23, 2009 at 9:11 AM, Hundredth Monkey <
stephan.a...@googlemail.com> wrote:

>
> thnx for reply,
> yes i' ve found proxy solutions before. i think its ugly because it
> will cost my traffic. all i want to do is to check a external page for
> a backlink. but i understand... u mean my browser tries to convert to
> javascript object...
> hmmm , seems theres realy no way to load cross domain text via ajax. :O
> (
>
> On 23 Sep., 18:04, Michael Geary <m...@mg.to> wrote:
> > It can't be done.
> >
> > Cross-domain JSON is actually JSONP, which uses a dynamic <script>
> element.
> >
> > You can load a <script> element from any domain; that's why JSONP works.
> >
> > If you can't get the other domain to give you JavaScript code such as
> JSONP,
> > then your only other option is to use a proxy on your server, so your
> server
> > fetches the HTML code from the other domain. Then your JavaScript code
> can
> > load that HTML with no problem.
> >
> > You can get proxy server code in a number of languages, such as this one
> in
> > PHP:
> >
> > http://developer.yahoo.com/javascript/howto-proxy.html#phpproxy
> >
> > http://www.abdulqabiz.com/blog/archives/2007/05/31/php-proxy-script-f...
> >
> > Search for:
> >
> > {yourlanguage} cross-domain proxy
> >
> > to find others.
> >
> > -Mike
> >
> > On Wed, Sep 23, 2009 at 8:27 AM, Hundredth Monkey <
> >
> > stephan.a...@googlemail.com> wrote:
> >
> > > hi,
> > > since a few days i try to load external html content from another
> > > domain. obviosly it is hard to access cross domain content wit
> > > javascript ajax methodes. first i' ve tried iframes but access denied.
> > > after that I' ve tried $.ajax but all request returned zero byte data
> > > from server.
> > > here is a way that seems to work but raise an error while processing
> > > data from text to json object
> >
> > >                        $.getJSON("http://example.com?jsoncallback=
> ?",null,
> > >                                        function(data){
> > >                                                alert(data);
> > >                                        });
> >
> > > i can see the server response in firebug and it requests the html
> > > data. but as i sayd i raise an error while converting to json. any
> > > chance to get raw data before jquery konversion? or maybe any other way
> > > (s) to request html data in text format from cross domain?
> >
> > > thanks in advance!
>

Reply via email to