0

I have a chat program using javascript and php ajax and after about 5 - setIntervals it begins to throw this error even when I don't perform anything the request still starts to error out after a while any suggestions??? my code is a basic textarea and is loaded using a json array that is returned the error is

SCRIPT7002: XMLHttpRequest: Network Error 0x2ef3, Could not complete the operation due to error 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));

and my 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"] . "&#13;&#10;";
 $i++;
}
}
$conn->close();
echo json_encode($aMess)
?> 

its a mess naming and indention and no validation but it works until errors out I thought about me not freeing a variable or running it to fast on setinterval I'm lost

WillardSolutions
  • 2,316
  • 4
  • 28
  • 38
John
  • 36
  • 1
  • 5
  • This things are better accomplished with sockets – Lelio Faieta May 10 '16 at 19:31
  • Did you find [this](http://stackoverflow.com/questions/14527387/script7002-xmlhttprequest-network-error-0x2ef3-could-not-complete-the-operati) Q&A on SO? Perhaps it gives some hints in the right direction? (see also EatPeanutButter's comment) – Marten Koetsier May 10 '16 at 19:43

0 Answers0