Jump to content

refresh form info without refreshing page


sdaniels

Recommended Posts

I have a link to a php/javascript chat room that somehow refreshes the form info without refreshing the whole page. this is great, and id like to mimic this showing the current users online. Only thing is that im a novice php coder and dont know squat about javascript. could someone more talented than I take a look at this and explain how its done?

the link to the page to see it in action is here:

[a href=\"http://www.pjduvivier.com/chatoo/\" target=\"_blank\"]http://www.pjduvivier.com/chatoo/[/a]

i believe this may be the code but i could be wrong:
[code]

<script>
      
function displayMessage() {
        var xhr_object = null;

if(window.XMLHttpRequest) // Firefox
                xhr_object = new XMLHttpRequest();
        else if(window.ActiveXObject) // Internet Explorer
                xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
        else { // XMLHttpRequest non support par le navigateur
                alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...utilisez firefox cela ne vous ferra pas de mal");
                return;
        }

    xhr_object.open("GET", "reload.php", true);

        xhr_object.onreadystatechange = function() {

     if(xhr_object.readyState == 4) {

         var chaine=xhr_object.responseText;
         var contentArray=chaine.split('X');
         var chaineText=contentArray[0];
         var listUser=contentArray[1];
         var object=document.getElementById('mon_texte');
         var userobject=document.getElementById('online');
        
          if (chaineText.length>4)
          {

         object.innerHTML= document.getElementById('mon_texte').innerHTML+chaineText;
         object.scrollTop=object.scrollHeight;
        
          }
            
         userobject.innerHTML=listUser;


        setTimeout( "displayMessage()",2500);}
        }
    xhr_object.send(null);
}

</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
[/code]
Link to comment
Share on other sites

You can also do this by used AJAX from JavaScript and use CSS to define where the information is to be displayed. From within Javascript you can update the <div>'s and <span>'s with the correct information. No reloading is done, just updates in place.

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.