how to check and get new message from db on real time in jquery ajax without page refresh -


i working on project,as trying check new inserted messages in db each user , echo when user chat without refreshing page see new message,but try using setinterval problem once user login messages wait 3 seconds , disappear chat.

now question how keep message , show new messages db

 setinterval(function(){     var id = $(".id").val();       //alert(id);       $.ajax({   type:'get',    url:"msg.php",    data:{id:id},    success: function(data){    $("#msgnot").html(data);    }  });     },3000);  msg.php   <?php     session_start();    include 'db.php';     if(isset($_get["id"])){      $ids = $_get["id"];         $sql = "select * answers userid='$ids' , msgstatus='0'";        $query = mysqli_query($con,$sql);        while($rows = mysqli_fetch_assoc($query)){        ?>       <div id="reply"><a href="read.php?id=<?php echo $rows["id"]; ?>"><?php echo "message ".$rows["replyid"]; ?>       <div id="m_active">       <?php          if($rows["msgstatus"] == "0"){                echo "<strong style='width:50px;text-align:center;background:red;color:white;'>"."1"."</strong><br>";          }else{          }         }           }       ?></a></div></div> 

as per comment: .html() empty element before appending new content (dom or text nodes):

when .html() used set element's content, any content in element replaced new content.

what want achieve append additional content, , using $('#msgnot').append(data) work case.

p/s: note should sanitising/stripping html tags user input on server side, since .append() inject string as-is, , users may exploit conduct xss attacks.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -