Javascript Error when updating client using AJAX call

0

I am trying to model a chat application on a browser(Firefox).Here I am trying to send the char inserted into a text area on one machine to another client and update its text area. I am trying to send the key pressed on the client using AJAX calls. Below is the function call that I have written :

function returnKeyFromCode(code)
{
 //Returns char code
};


function keyPress(e)
{

    var textReplace = document.getElementById("textReplace");
    var keyPressed = returnKeyFromCode(e.which)  ;
    textReplace.innerHTML = keyPressed;
    var locationReplace = document.getElementById("location");
    locationReplace.innerHTML = mainDoc.selectionStart;

    xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=function(){};
    xmlhttp.open("POST","http://localhost:5000?key=" + keyPressed + "&pos=" +mainDoc.selectionStart +"&revno=1&param=EOS",true);
    xmlhttp.send("Stuff");
};

At the client side, when the char is received the following error is displayed on the fire bug console: '0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]' .

Before sending the data, a persistent connection is being set up between client ans server using another Ajax call.

javascript
ajax
xmlhttprequest
asked on Stack Overflow Mar 9, 2012 by Mask • edited Mar 9, 2012 by Josh

1 Answer

0

It looks like you've edited some of your code before posting this question, so I can only speculate, but based on the error, i'd guess at some point you're sending null to this function: xmlhttp.send("Stuff");

Try doing a null check on the data before you send it, or possibly make sure whatever starts the send process is in a document ready, so that you're not trying to grab data from an undefined text element.

answered on Stack Overflow Mar 9, 2012 by Josh

User contributions licensed under CC BY-SA 3.0