开发者

AJAX 2nd Request and IE6

开发者 https://www.devze.com 2023-02-16 21:19 出处:网络
Hey. I\'m using AJAX (no Framework) to list Documents contained in Directories on the Server. First:The \"getfiles.php\" asks MySQL if the directory is password protected. If yes it returns \"!pw!\".

Hey.

I'm using AJAX (no Framework) to list Documents contained in Directories on the Server.

First:

The "getfiles.php" asks MySQL if the directory is password protected. If yes it returns "!pw!".

So if the responseText matches "!pw!" the second request should be triggered with the entered password and return the Documentlist.

Chrome and FireFox 3+ & 4 are doing well... but IE6 still refuses to load the List, after the password has typed in.

P.S.: Sorry for my bad English.

function showFiles(str)
{
var xmlhttp = false;
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
       xmlhttp = n开发者_JAVA百科ew XMLHttpRequest();
       if (xmlhttp.overrideMimeType) {
           xmlhttp.overrideMimeType('text/xml');
       }

   } else if (window.ActiveXObject) { // IE
       try {
           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
       }
   }

   if (!xmlhttp) {
       alert('Unfortunately you browser doesn\'t support this feature.');
       return false;
   }    
xmlhttp.onreadystatechange=function()
  {
  switch (xmlhttp.readyState)
    {
    case 4:
        if (xmlhttp.status==200)
            {
            if (xmlhttp.responseText.match("!pw!"))
                {
                var pw = prompt ("A Password is required!\nIf you don\'t have the Password, please ask your Colleagues","Passwort needed");
                xmlhttp.open("GET","getfiles.php?f="+str+"&pw="+pw,true);
                xmlhttp.send();
                }
            else
                {
                document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                }
            }
            break;
    default:
        document.getElementById("txtHint").innerHTML="<div align=\"center\"><img src=\"../_img/wait.gif\"/></div>";
        break;
    }

  }
xmlhttp.open("GET","getfiles.php?f="+str,true);
xmlhttp.send();
}


Instantiate a new XMLHttpRequest each time you start a new request instead of reusing the previous instance. That should fix it.

0

精彩评论

暂无评论...
验证码 换一张
取 消