php - How do i pass my chatroom id to my ajax call? -


i want call id when user select different room. different have different id how let ajax know room have enter?

and have use ajax call 2 function php is

  • chatnew.php insert message
  • chatmessage.php load message

i have used $chatroomid =$_get['chatroomid']; call id seem no working , error

-localhost/pme/main/chatroom.php?chatroomid=1 << how chatroomid

here chatrooms.php have use sql statement select chatroom out database

 <td>         <a onclick="poll" href="chatroom.php?chatroomid=<?php echo $row['id'];?>">             <div>                 <p>                     <?php echo ($row['name']); ?>                 </p>             </div>         </a>     </td> 

this js file

function submitchat(){         var message = chatroom.message.value;     if(chatroom.message.value == ''){         alret('you didnt input message');         return;     }      var xmlhttp = new xmlhttprequest();      xmlhttp.onreadystatechange = function(){         if(xmlhttp.readystate == 4 && xmlhttp.status == 200){             document.getelementbyid('inner').innerhtml = xmlhttp.responsetext;         }     }      xmlhttp.open('get','chatnew.php?&message='+message,true);     xmlhttp.send();     $('.chatroom-message-container').scrolltop($('.chatroom-message-container').get(0).scrollheight); }  $(document).ready(function(e){      $.ajaxsetup({cache:false});     setinterval(function(){$('#inner').load('chatmessage.php');}, 2000);      $(".sendmessage-btn").click(function(){         $("#area-message").val('');          });   });  (function poll() {     settimeout(function(){         $.ajax({             url:"chatroom.php?chatroomid=id",              success:function(data)             {                 setvalue(data.value);             },             datatype:"json",             complete:poll         });     },     30000             );   }); 

you can use ajax data option send variable , can on chatroom.php php get.

(function poll() { settimeout(function(){     $.ajax({         url:"chatroom.php",          data:{chatroomid:id},         success:function(data)         {             setvalue(data.value);         },         datatype:"json",         complete:poll     }); },30000);   }); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -