javascript - setInterval() prevents other JS from running by reloading page constantly. Not a duplicate -




this based on different subject , question not duplicate , plus other guys can't answer new discovery's other post ways had chat on other post can find here link

so story here made successful private message system can see partners messages automatically. decided put js features ajax response page aka chat.php responsible in

showing new messages coming in constantly. copy code other guys code bought , every thing worked. every time add javascript code chat.php disappear fast or not show @ found out working. original author code rely on setinterval()

show new messages coming in made of js go away fast. there other way can keep ability see new messages coming in , prevent js disappearing? know it's possible because when have web apps facebook etc.. don't deal problem

any other method or advice appreciated , removed js code added chat.php guys can give me advice on using other methods instead of focusing on trouble shooting here. ok here's files , said's setinterval(function(){ajax()},1000); in index.php file. causing problem.

index.php

<?php include("0/instructions/php/session.php"); $session = $_post['set_session']; $session = $_session['set_session']; $messenger_id = $user_id; $partner_id= $_post['partner_id'];   ?> <!doctype html> <html> <head> <meta name="viewport" content="width=device-width"> <meta charset="utf-8"> <title>chat system in php</title> <link rel="stylesheet" href="style.css" media="all"/> <script> function ajax() { var req = new xmlhttprequest(); req.onreadystatechange = function(){ if(req.readystate == 4 && req.status == 200) {  document.getelementbyid('chat').innerhtml = req.responsetext;  } } req.open('get','chat.php',true); req.send();  } setinterval(function(){ajax()},1000); </script> </head> <body onload="ajax();"> <div class="main_container"> <div id="container"> <div id="chat_box"> <div id="chat"></div> </div> </div> <form method="post" action=""> <div style="display: none;"> <input type="text" name="conversation_id" placeholder="conversation_id"  value="<?php echo $session; ?>"/> <input type="text" name="member_name" placeholder="member_name" value="<?php echo $user_first_name;?> <?php echo $user_last_name;?>"/> </div> <textarea name="message" placeholder="enter message"></textarea> <input type="submit" name="submit" value="send it"/> </form> <?php if(isset($_post['submit'])){ $conversation_id = $_post['conversation_id']; $member_name= $_post['member_name']; $message= $_post['message'];  $query = "insert messages_x1 (conversation_id,member_name,message) values ('$conversation_id','$member_name','$message')";  $run = $connect->query($query);  if($run) { echo "<div id='hide_audio'><embed loop='false' src='chat.mp3' hidden='true' autoplay='true'/></div>"; }  } ?> </div> </body> </html> 

chat.php

<?php include("0/instructions/php/session.php");  $session = $_session['set_session'];  $query= "select * messages_x1 conversation_id='$session' order message_id desc"; $run = $connect->query($query);  while($row = $run->fetch_array()) : $messenger_id = $row['messenger_id']; ?> <!doctype html> <html> <head> <style> .close_button {     position: relative;     float: right; left: 8px;     font-size: 25px;     text-decoration: none;   cursor:pointer; bottom: 3px; color: white; background-color: transparent; width: 30px; height: 20px; text-align: center; }  .close_button p{ position: relative; top: -15px; }  .close_button:hover {   color: red; } </style> </head> <body> <div id="chat_data"> <span style="color:green;"><?php echo $row['member_name']; ?></span> : <span style="color:brown;"> <?php echo  "<a class='close_button' href=\"delete.php?message_id=$row[message_id]\"onclick=\"return confirm('are sure want delete?')\">&times;</a>";?><br><?php echo $row['message']; ?></span>  </div> <body> </html> <?php endwhile;?> 

note: ignore php variables don't make logical sense linked session or include not causing problem.

screen shot





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -