javascript - getXMLHTTP() issue -


i have following code:

<script type="text/javascript" language="javascript"> <!-- function getxmlhttp() { //function return xml http object         var xmlhttp=false;             try{             xmlhttp=new xmlhttprequest();         }         catch(e)    {                     try{                             xmlhttp= new activexobject("microsoft.xmlhttp");             }             catch(e){                 try{                 req = new activexobject("msxml2.xmlhttp");                 }                 catch(e1){                     xmlhttp=false;                 }             }         }          return xmlhttp;     }      function wait1()     {         document.getelementbyid('comment').innerhtml="please wait...";         }      function getcomment(strurl) {                  var req = getxmlhttp();          if (req) {              req.onreadystatechange = function() {                 if (req.readystate == 4) {                     // if "ok"                     if (req.status == 200) {                                                 document.getelementbyid('comment').innerhtml=req.responsetext;                                             } else {                         alert("there problem while using xmlhttp:\n" + req.statustext);                     }                 }                             }                         req.open("get", "comment_form.php", true);             req.send(null);         }      } //--> </script>      <div id="comment"> <form  action="javascript:get(document.getelementbyid('comment'));wait1()" method="post" enctype="multipart/form-data" > <input type="submit" name="submit" value="post comment" /> </form> </div> 

i sure used same in past running smoothly, doesn't seem working. think messed there, not able figure out.

i thankful if solution.

the 1 bug in above code, found, was: getcomment(strurl) function takes argument, never used. "comment_form.php" should replaced function's argument instead. and, since software's soft, renamed strurl easier-to-read-and-spell "url".

(that div presented opened, not closed, formatting oversight, take it. wait1 function unused here, too.)

there's no need add deprecated "language" attribute script tag, nor wrap js code in html comments.

function getxmlhttp() {     var x = false;     try {         x = new xmlhttprequest();     }     catch(e) {         try {             x = new activexobject("microsoft.xmlhttp");         }         catch(ex) {             try {                 req = new activexobject("msxml2.xmlhttp");             }             catch(e1) {                 x = false;             }         }     }     return x; }  /* todo: ever used? */ function wait1() {     document.getelementbyid('comment').innerhtml = "please wait..."; } function getcomment(url) {     var req = getxmlhttp();     if (!req) {         // complain early, instead of nesting         alert('unable set xhr object.');          return;     }     req.onreadystatechange = function() {         if (req.readystate == 4) {             // if "ok"             if (req.status == 200) {                 document.getelementbyid('comment').innerhtml = req.responsetext;             } else {                 alert("there problem while using xmlhttp:\n" + req.statustext);             }         }     };     req.open("get", url, true); // "true" stands "async", when not default?     req.send(null); // not add content (null); when not default? } 

i added questions code.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -