Forum Moderators: open

Message Too Old, No Replies

Is AJAX Required to insert html from other domain into a <div>?

AJAX, Javascript

         

jason1989

6:40 pm on Jan 8, 2009 (gmt 0)

10+ Year Member



I've never used AJAX before and have a little experience with Javascript. I'd like to insert some html generated from a web application into a static html page.

DOMAIN 1 - I have a web application that returns the following dynamic html (please note that there are no other html tags such as <body>, etc. generated):

<table>
<tr><td>some db data</td></tr>
<tr><td>some db data</td></tr>
</table>

DOMAIN 2 - This domain is a static html website that I'd like to insert the table above into:

<html>
...
<div id="MyID">Insert html table from other domain here.</div>
...
</html>

I have some more questions about this but will wait until I know if AJAX is required to do this.

Thank you!

jason1989

7:36 pm on Jan 8, 2009 (gmt 0)

10+ Year Member



I found some stuff here on the forum to help me. It seems that AJAX is required.

I also found threads talking about AJAX libraries, but for my requirements, I don't think I need such large AJAX suites.

Pretty much, I just want to insert text from one URL into a div.

Is there a small routine or lib available that someone can recommend for this? I really don't need to do any fancy AJAX stuff on my page.

Thank you

methode

3:43 pm on Jan 9, 2009 (gmt 0)

10+ Year Member



As far as I'm concerned, you definitely need an XHR to get the data from the page containing the data.

I usually don't suggest anyone to use a framework, but since you're new to AJAX, please take a look on the following page: [docs.jquery.com...] (load( url, [data], [callback] ))

Explanation of why i suggest now a framework for ajax: simply because it's way easier than creating the crossbrowser functions which can make XHR.

XHR = XMLHttpRequest aka(-ish) AJAX

jason1989

8:12 pm on Jan 9, 2009 (gmt 0)

10+ Year Member



Thanks for the link. I looked at jQuerry's AJAX documentation and it looks good and is very easy to get things done with.

I studied up on using XMLHttpRequest and it actually seems to be much easier than I had envisioned it to be. Like you suggested, I'm going to begin working without an AJAX framework for now. Alternatively, I can see how useful a framework would be when changing the appearance of your page (i.e. widgets, animation...).

Thank you

methode

8:31 pm on Jan 9, 2009 (gmt 0)

10+ Year Member



OK. If you want to go on the other way, I'd recommend the place where I begun to really understand what's AJAX and how to use it. It's the W3 school, so, it's safe link: [w3schools.com...]

Try to understand the examples, then when you think you understand, try to grab the snippets from their pages and put them in your own code. It's easier than making IE crash, so, have a great fun :)

[edit]W3C and w3 is not the same i guess :¦

jason1989

9:11 pm on Jan 9, 2009 (gmt 0)

10+ Year Member



Excellent snippets! Thank you!

Demaestro

9:41 pm on Jan 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You did say that you want to pull data from one domain to another right?

To clarify you want to take
example.com/example.xml

and put it into this page using Ajax?
example2.com/example.html

If so you can't do this with Ajax, part of the built in security with XMLHttpRequest is that you can't request data from a different domain.

Perhaps I have misunderstood your question but if you are using 2 seperate domains then maybe an iFrame is the way to go.

[edited by: Demaestro at 9:42 pm (utc) on Jan. 9, 2009]

methode

6:13 am on Jan 10, 2009 (gmt 0)

10+ Year Member



I'm sorry, I know am new, but still: How does the Friendconnect widget works then? It sends two XHR to Google requesting data, and it does receive it. Or the AJAX Search Api. The same.