javascript - XMLhttprequest issues -


i'm trying work on xmlhttprequests isn't working. when inserting alert box receive status of 0. cant quite figure out what's wrong.

function submitchat() {      if (form1.uname.value != '' && form1.msg.value != '') {        var uname = form1.uname.value;        var msg = form1.msg.value;        var xmlhttp = new xmlhttprequest();        alert(xmlhttp.status);        xmlhttp.onreadystatechange = function() {          if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {            document.getelementbyid('chatlogs').innerhtml = xmlhttp.responsetext;            }        }        xmlhttp.open("get", "insert.php?uname=" + uname + "&msg=" + msg, true);        xmlhttp.send();      } else {        alert("all fields mandatory !!!");        return;      }  }
<form name="form1" action="#">`` chatname:    <input type="text" name="uname" />    <br/>    <textarea name="msg"></textarea>    <a href="javascript: submitchat()"> send</a>     <br/>    <br/>  </form>    <div id="chatlogs">    loading chat history !!!!!!!!!!  </div>

you should .open() before alert. code becomes this:

function submitchat() {     if (form1.uname.value != '' && form1.msg.value != '') {          var uname = form1.uname.value;          var msg = form1.msg.value;         var xmlhttp = new xmlhttprequest();         xmlhttp.open("get","insert.php?uname="+uname+"&msg="+msg,true);         alert (xmlhttp.status);         xmlhttp.onreadystatechange = function() {             if(xmlhttp.readystate==4 && xmlhttp.status==200) {                 document.getelementbyid('chatlogs').innerhtml = xmlhttp.responsetext;               }          }          xmlhttp.send(null);         } else {         alert("all fields mandatory !!!");         return;     } } 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -