我有一个使用javascript和php ajax的聊天程序和大约5 - setIntervals后它开始抛出此错误,即使我没有执行任何请求仍然开始出错一段时间后任何建议???我的代码是一个基本的textarea,并使用返回的json数组加载 错误是
SCRIPT7002:XMLHttpRequest:网络错误0x2ef3,由于错误00002ef3无法完成操作
var vMess = setInterval(GetInfo, 5000);
var vRoomName = "Lobby";
function GetInfo()
{
var myArr = ["Banana", "Orange", "Apple", "Mango"];
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myArr = JSON.parse(xmlhttp.responseText);
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
var vText;
// Get the size of an object
var size = Object.size(myArr);
var i;
for(i = 0; i < size; i++) {
vText += myArr[i];
}
document.getElementById("Welcome").innerHTML = vText;
}
};
xmlhttp.open("POST", "GetInfo.php", true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send('x=' + encodeURIComponent(vRoomName));
和我的php
<?php
session_start();
//Set Connection Variables
$servername = "localhost";
$username = "stuff"
$password = "stuff";
$dbname = "stuff";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$i = 0;
$sql = "SELECT * FROM Chat_Rooms WHERE Room_Name = '" . $_POST['x'] . "'";
//Execute Query
$result = $conn->query($sql);
if($row = $result->fetch_assoc())
{
//Store Session Variables
$RoomId = $row['Room_Id'];
}
$sql = "SELECT * FROM Chat_Line WHERE Room_Id = " . $RoomId . " ORDER BY Message_Date" ;
//Execute Query
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$aMess[$i] = $row["Message_Date"] .": " . $row["Message"] . " ";
$i++;
}
}
$conn->close();
echo json_encode($aMess)
?>
它是一个混乱的命名和缩进,没有验证,但它可以工作,直到出错我想到我没有释放变量或在setinterval上快速运行它我丢失了