javascript - Ajax script fails in IE8 -


the following script executes , works fine in safari, chrome , firefox - not in ie8. unfortunately ie8 1 of targeted browsers bit of problem. since don't have lot of experience ajax i'm not sure begin looking either.

i've noted ie reports error on line 15 (marked **) doesn't make sense if-else should stop looking @ line.

function getnames(str) {     var xmlhttp;     // clear previous queries     if(str.length == 0){         document.getelementbyid("txthint").innerhtml = "";         return;         // due high number of possible hits we'll demand 3 chars         // before start querying.     }else if(str.length < 3){         return ;     }     if (window.xmlhttprequest){ // code ie7+, firefox, chrome, opera, safari         xmlhttp = new xmlhttprequest();     }else{ // code ie6, ie5         **xmlhttp = new activexobject("microsoft.xmlhttp");**     }     xmlhttp.onreadystatechange = function (){                 if(xmlhttp.status == 200 && xmlhttp.readystate == 4){             // string get_names.php comma separated             var arr = xmlhttp.responsetext.split(",");             // ul list want our names in             var ul = document.getelementbyid("names");              // clear list each key in             if(ul.haschildnodes()){                 while(ul.childnodes.length >= 1){                     ul.removechild(ul.firstchild);                 }             }             // step trough string in array form             for(var = 0; < arr.length; i++){                 // :@ means we've reached end of applicable names.                 if (arr[i] != ":@") {                     var li = document.createelement("li");                     li.innerhtml = newlistitem = arr[i];                     // inserts current name list.                     ul.insertbefore(li, ul.getelementsbytagname("li")[0]);                 }             }         }     }     xmlhttp.open("get", "./ext/get_names.php?q=" + str, true);     xmlhttp.send(); } 

you should first check readystate , then check status. common error reported ignored in browsers. i'm not sure solution problem, since haven't provided error message, it's hard further.

if(xmlhttp.readystate == 4 && xmlhttp.status == 200) {    // code ... } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -