Hai... I'm new to Ajax.. I've seen many cool site pumped with ajax requests. How can I fill the content with ajax responseText ONLY after the page structure has been fully loaded?

is it matters if the file is not an html? is .html file faster to render than .php?
is it matter if i use tables instead of floating divs? which is faster to render?
From what I've learned so far, I have to put ajax requests before the </body> tag comes, but i still have unresolved questions. any tips on this would be appreciated

Recommended Answers

All 4 Replies

> How can I fill the content with ajax responseText ONLY after the page structure has been fully
> loaded?

Attach a listener (function) to the onload event handler which would load all the values using Ajax requests only after the page has been loaded.

> is it matters if the file is not an html? is .html file faster to render than .php?

This question doesn't make sense. The client always gets to see HTML; PHP / Servlets / ROR etc. are just server side constructs which add dynamic nature to the pages being presented to the client. If your pages don't have any dynamic content, go with HTML otherwise with any server side language of your choice.

I've tried your suggestion. it worked fine . Thank you :)

but on one page, I put some data that i fetched from mysql table. it's big and takes some time to render. it become slows on that part.

so, i change my method. I made that into an ajax request too. Now, everything starts to load after the page fully displayed just like i wanted.

but [again], I have some link that calls an ajax function on the mysql content (scriptaculous effect on the content item's div) that didn't work after I changed it. Firebug said something like 'news-xxx' have no properties. I look on 'view source' .. and.. there's no div named 'news-xxx', although he content displayed just fine on my screen.

I just found that if I got the content directly with normal request, the content displayed on the source.
When I use ajax request, the content renders alright too but didn't show up on the page source.. just a blank div
How can the ajax response text physically there (on view source) ? I think this is the problem why my ajax function didn't work.
any pointers?

> When I use ajax request, the content renders alright too but didn't show up on the page
> source

This is because the data is fetched asynchronously only after the response is committed to the client. So what you see is the original response rendered by the server; it won't show you the data dynamically fetched using Ajax. Instead of bringing in the entire DIV using an Ajax request, place an empty DIV with an ID of 'news-xxx' on your page and fetch it's contents using Ajax.

As far as viewing the current state of DOM is considered, a Firefox extension DOM Inspector might be of some help.

hmmm, interesting... let me try that, but i'm confident it will work

Thanks a lot, s.o.s :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.