Ajax UPDATE div
#1
Posted 21 December 2007 - 10:51 PM
#2
Posted 22 December 2007 - 12:20 AM
To update a div with JavaScript, you typically change the innerHTML attribute.
#3
Posted 22 December 2007 - 02:55 PM
function jah_switch(url,target) { if (document.getElementById(target).innerHTML != '') { document.getElementById(target).innerHTML = ''; } else { jah(url,target); } } function jah(url,target) { // native XMLHttpRequest object document.getElementById(target).innerHTML = '<span class="ajah_waiting"><a href="java script:jah(\''+url+'\',\''+target+'\');">sending...</a></span>'; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = function() {jahDone(target);}; req.open("GET", url, true); req.send(null); // IE/Windows ActiveX version } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = function() {jahDone(target);}; req.open("GET", url, true); req.send(); } } } function jahDone(target) { // only if req is "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { results = req.responseText; document.getElementById(target).innerHTML = results; } else { document.getElementById(target).innerHTML="jah error:\n" + req.statusText; } } }
put tht into a .js file
basically to update a div use
jah('myurlhere','mydivhere');
hope tht helps
#4
Posted 22 December 2007 - 04:58 PM
#5
Posted 22 December 2007 - 06:38 PM
setInterval('jah(\'myurlhere\',\'mydivhere\');',10000);
and wala, 10 second update
Edited by curthard89, 22 December 2007 - 06:41 PM.
#6
Posted 22 December 2007 - 08:26 PM
#7
Posted 23 December 2007 - 01:04 AM
I'm sorry, but with as brief as his question was, how can you be sure my answer was not what he was asking for? Without a proper question, i can only do so much. You were right to take it in a different light, but to me, your answer was the exact same, just a little more informative (although, i would have picked a better function name... that's just personal preference).thats really not what hes asking for lol, well it kinda is, but he wants ajax function, ok here u go
Well, I was hoping I could do it automatically wtihout clicking anything. see, i'm not a javascript proger. I'm learning basics right now. soo anything helps. I guess it's like a countdown if you think about it. Every 10 seconds it'll refresh if you understand what I'm saying? I know it can be done in AJAX so ya
Still learning? Still confused?ok im still confused! lol im so sory
and
http://www.google.co...ript settimeout
http://www.google.co... banner refresh
http://www.pixel2lif...als/javascript/
http://www.pixel2lif...?showtopic=8980
If you could give the exact breakdown of what is supposed to happen, how you're going about doing it, and what is going wrong, we could probably help more.
#8
Posted 23 December 2007 - 12:10 PM
#9
Posted 23 December 2007 - 12:16 PM
#10
Posted 23 December 2007 - 12:57 PM
Anyways, if you do look into it, updating a DIV is as simple as
$objResponse->addAssign("reqbox", "innerHTML", $message);
reqbox would be the DIV id, $message would be what you are updating it with. If you look into it and need help, send me a PM.
#11
Posted 04 June 2008 - 09:37 AM
I found this thread while searching Google for a way to auto refresh a div every 2 minutes using ajax
I tried the code above and it works great in Safari but Internet Explorers it refreshes the div but pulls a cached version. Is there a way to stop ie from using a cached version of the page?
Many thanks for your help
Steven
#12
Posted 04 June 2008 - 04:55 PM
Ref: http://php.net/manua...tion.header.php Example #2
#13
Posted 04 June 2008 - 05:32 PM
#14
Posted 30 August 2008 - 07:07 AM
It seems to do exactly what I want, however it 'clones' my DIVs, not just the one with the ID but all of them and I can't seem to understand why.
Anyone know how to resolve this?
Kind Regards,
Nick.
#15
Posted 30 August 2008 - 03:32 PM
#16
Posted 31 August 2008 - 04:28 AM
Here is my DIV:
What happens is that when it refreshes, it creates a copy of the DIVs.
Edited by nicksource, 31 August 2008 - 01:56 PM.
#17
Posted 31 August 2008 - 12:16 PM
setInterval('jah(\'http://www.rc-manager.com/chat.php\',\'chatdiv\');',8000);Could you post the code for the jah() function?
Edited by rc69, 31 August 2008 - 12:17 PM.
#18
Posted 31 August 2008 - 01:57 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users