2010-06-20 2 views
1
<script type="text/javascript"> 
    function showUser(str) { 
     if (str == "") { 
      document.getElementById("txtHint").innerHTML = ""; 
      return; 
     } 
     // code for IE7+, Firefox, Chrome, Opera, Safari 
     if (window.XMLHttpRequest) { 
      xmlhttp = new XMLHttpRequest(); 
     } else { // code for IE6, IE5 
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
     } 
     xmlhttp.onreadystatechange = function() { 
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
       document.getElementById("txtHint").innerHTML = xmlhttp.responseText; 
       //document.myForm.text1.value=.innerHTML=xmlhttp.responseText; 
      } 
     } 
     xmlhttp.open("GET", "getuser.php?q=" + str, true); 
     xmlhttp.send(); 
    } 
</script> 

</head> 

<body> 
<form name="myForm"> 
    <p>Selec the Menu : 
     <select name="users" onchange="showUser(this.value)"> 
      <option value="">Select ID</option> 
<?php do { ?> 
      <option value="<?php echo $row_rscustomer['customer_number']?>"><?php echo $row_rscustomer['customer_number']?></option> 
<?php } while ($row_rscustomer = mysql_fetch_assoc($rscustomer)); 
    $rows = mysql_num_rows($rscustomer); 
     if ($rows > 0) { 
      mysql_data_seek($rscustomer, 0); 
      $row_rscustomer = mysql_fetch_assoc($rscustomer); 
     } ?> 
     </select> 
    </p> 
    <p>&nbsp;</p> 
    <p> 
     <input name="text1" type="text" 
       value="<?php include (" getuser.php");?>"/> 
    <p> 
</form> 
<div id="txtHint"></div> 

답변

2

안녕하세요 - AJAX onreadystatechange 함수에서 xmlhttp.status == 200을 조건에 추가했습니다. 일부 브라우저에서는 AJAX가 클라이언트 측 언어이기 때문에 지원되지 않습니다. 구성원 상태가 인 경우 사용자 브라우저에서 지원하지 않으면 기본값은 입니다. 정의되지 않음 또는 0입니다. 값이 절대로 200이 아니어도 해당 조건의 블록은 실행되지 않습니다.

나는 xmlhttp.status의 == 200 조건을 제거하고, 단지 xmlhttp.readyState에 의존하는 것이 좋습니다. 내가 AJAX로 처음 시작할 때이 문제가 발생했습니다.

관련 문제