我的代码一直在崩溃xampp

时间:2017-05-25 02:36:54

标签: javascript php xampp

我试图创建一个在chat_active = 1时自动运行的功能,但它只是崩溃xampp并使我的cpu非常高并且网站不会响应..这里是我的javascript和php文件崩溃xammp的代码



function chat_refresh(){
		document.forms["chatname"]["namechat"].value = id;
		var username = document.forms["chatname"]["namechat"].value;
		$.post( ('php/friend/chat.php'), $('#chatname :input').serializeArray(),
			function(data){
				$('#chats').html(data);
				var element = document.getElementById('chat-panel');
				element.scrollTop = element.scrollHeight - element.clientHeight;
				document.getElementById("chat").focus();
				active()
				});
};
function active(){
	if(chat_active == 1){
		var time = 1000; // ms
		var endtime = 10000;  // ms
		var counter = 0;
		var start = setInterval(function(){
    chat_refresh()
    if(counter === endtime){
       clearInterval(start);
    }
    counter += time;
}, time);
	}
}

<?php
session_start();
if(isset($_SESSION['users']) == ""){
echo '<script type="text/javascript">','index();','</script>';
}

require '../../php/dbConnect.php';
if (isset($_POST['namechat'])) {
$username = $_POST['namechat'];
}
$user = $_SESSION['users'];

$query = ("SELECT * FROM `chat` WHERE `username_receive` = '$user' && `username_send` = '$username' || `username_receive` = '$username' && `username_send` = '$user'");
$response = mysql_query($query);
while($row = mysql_fetch_assoc($response )) {
  if($row['username_send'] == $username)
  echo '
  <div>
    <img id="profile-image" src="img/'. $row['image'] .'" class="small-circle " style="display: inline-block; margin: 2% 0 0 0">
    <label id="chat-bubble" class="w3-input w3-text-white overlay border-remove round-edge " style="width: 70%; word-wrap: break-word;display: inline-block; margin: 0 0 2% 0">'. $row['chat'] .'</label>
  </div>
';
else
  echo'
    <div>
      <label id="chat-bubble" class="w3-input w3-text-white overlay border-remove round-edge " style="width: 70%; word-wrap: break-word;display: inline-block; margin: 0 0 2% 0">'. $row['chat'] .'</label>
      <img id="profile-image" src="img/'. $row['image'] .'" class="small-circle " style="display: inline-block; margin: 2% 0 0 0">
    </div>
    ';


}
?>
&#13;
&#13;
&#13;

0 个答案:

没有答案