View Full Version : Ajax script needed
Eccentric
15-09-2007, 12:15 PM
need a way to refresh a div every 20 seconds :S it is possible ive seen the script where abouts before but cannot re find it :( +rep for all help :P
ive found a way round using iframes at last :D
VistaBoy
15-09-2007, 12:29 PM
I have typed getting some thing like this but when i tryed it did not work and i have ask on many forum so i would like some thing like this to so i do hope some one can help Eccentric and me to :)
Eccentric
15-09-2007, 12:43 PM
Lol i cant remember wher i saw it :S
Invent
15-09-2007, 12:43 PM
Make a function which loads the html into the DIV.
Then just use setInterval() to make it run the function every 20 seconds.
Eccentric
15-09-2007, 01:13 PM
right simon,
i have this so far,
function LoadPage(page,usediv) {
// Set up request varible
try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { alert("Error: Could not load page.");}
//Show page is loading
document.getElementById(usediv).innerHTML = 'Loading Page...';
//scroll to top
scroll(0,0);
//send data
xmlhttp.onreadystatechange = function(){
//Check page is completed and there were no problems.
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
//Write data returned to page
document.getElementById(usediv).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", page);
xmlhttp.send(null);
//Stop any link loading normaly
}
what do i do now :P
L!!nK
15-09-2007, 01:15 PM
put it in your source web page
Eccentric
15-09-2007, 01:20 PM
function LoadPage(page,usediv) {
// Set up request varible
try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { alert("Error: Could not load page.");}
//Show page is loading
document.getElementById(usediv).innerHTML = 'Loading Page...';
//scroll to top
scroll(0,0);
//send data
xmlhttp.onreadystatechange = function(){
//Check page is completed and there were no problems.
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
//Write data returned to page
document.getElementById(usediv).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", page);
xmlhttp.send(null);
//Stop any link loading normaly
}
setInterval('LoadPage()', 2000);
i know have that but i believe it isnt working :(
Invent
15-09-2007, 02:40 PM
Change:
setInterval('LoadPage()', 2000);
To:
setInterval('LoadPage("thepageyouwanttoload.php", "div you want the page to show in")', 2000);
Eccentric
15-09-2007, 04:25 PM
Thanks si, ill try that now.
Edit;
Simon you are a star my friend. +rep :(! need to spread to be honest :|
Eccentric
15-09-2007, 08:35 PM
UPDATE:
i know see double of everything its to do with that piece of ajax :|
Baving
15-09-2007, 08:51 PM
You don't have to use ajax for this purpose, there is another way of doing it which is simpler and without ajax.
<script>
function reload_div(page,div) {
window.open(page,div);
setInterval('reload_div("'+page+'","'+div+'")',20000);
}
</script>
Then just call the javascript function on page load.
Eccentric
15-09-2007, 08:54 PM
would that open in the div the other question is would it work :S
Baving
15-09-2007, 08:55 PM
Yes the window.open(pageurl,window) allows you to open up pages into a div without refreshing the page. It is just simple javascript
Eccentric
15-09-2007, 09:01 PM
Ill try it :) Thanks, repped if i can mate.
according to my technical director it wouldnt work
setInterval('reload_div("'+page+'","'+div+'")',20000);
Would create a continuous loop
window.open(page,div);
Would open a new window
but thats according to him :)
VistaBoy
16-09-2007, 12:00 AM
Did you end up getting this to work or getting the code if so can you post it here so we can see :P
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.