PDA

View Full Version : AJAX - When page loads, load it into a DIV.



Jahova
27-05-2008, 04:02 PM
- SOLVED -

I've got my AJAX working, so if you click a link, It will load the page into the selected DIV.


But how would I load somthing into the div, when the rest of the site loads, if you know what I mean.


***


So say when you visit mysite.com - The layout loads.
But atm I have the div with just 'AJAX CODE HERE', as text, in it.
I want some AJAX code that'll make home.html load as soon as someone visits mysite.com.


***


I'm awkward at explaining this but here's some help;
When a link is clicked; javascript:ajaxpage('home.html', 'content');
Div HTML; <div id="content" class="style3">AJAX CODE HERE</div>


The AJAX CODE HERE is what shows when the page first loads.


- TomSpit


EDIT: At the moment, I am using; http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

Invent
27-05-2008, 04:03 PM
<script>
window.onload = ajaxpage('home.html', 'content');
</script>
That should work, or you can simply modify your <body> tag to:



<body onload="ajaxpage('home.html', 'content');">

Jahova
27-05-2008, 04:10 PM
Thanks alot,
I used the bottom one and it works great.

I'm learning AJAX and trying to improve my overall coding, and I was just stuck on this small bit, so thank you.

+ Reppingly
- Tom

Invent
27-05-2008, 04:11 PM
Good to hear :)!

Jahova
27-05-2008, 05:11 PM
New problem:
On the same page, I have another div, that I want to load another page on.
How would I do that?

I have tried adding;
<body onload="ajaxpage('content/home.html', 'content');" onload="ajaxpage('content/home.html', 'content');">

And also;
<script>
window.onload = ajaxpage('home.html', 'content');
</script>

But it doesn't seem to be working.

- Tom

Invent
27-05-2008, 05:18 PM
All you need to do is add the ajaxpage() function again to to the body onload, like this:



<body onload="ajaxpage('home.html', 'content'); ajaxpage('newpage.html', 'newdiv');">

Jahova
27-05-2008, 05:42 PM
Thanks for all this help.
And now another BIG problem.

I have cutenews on my site, and when I click to go into full story.
I don't know how to make it load into the div.

As it's cutenews and it's used to loading in frames or new pages, now it will load into a new page but I don't know how to make it load into the div.

- Tom

Invent
27-05-2008, 06:33 PM
To fix that you need to change your shows.inc.php file so that all the links run the javascript function instead of loading a page.

If you can't do this yourself, I'll do it for you when I get a chance :)

Jahova
27-05-2008, 07:20 PM
If you could do it please =D

Want to hide these adverts? Register an account for free!