未触发onchange方法

    <html>
     <head>
      <script>
       function showUser(str) {
       if (str == "") {
         document.getElementById("txtHint").innerHTML = "";
         return;
       } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.send();
      }
    }
    </script>
    </head>
    <body>

    <form>
     <select name="users" onchange="showUser(this.value)">
     <option value="">Select a person:</option>
     <option value="1">Peter Griffin</option>
     <option value="2">Lois Griffin</option>
     <option value="3">Joseph Swanson</option>
     <option value="4">Glenn Quagmire</option>
     </select>
    </form>
     <br>
     <div id="txtHint"><b>Person info will be listed here...</b></div>

    </body>
    </html>

The page shows the dropdown list. However, it seems the onchange method is not triggered. I don't get any return from the php. The php code is here. https://www.w3schools.com/php/php_ajax_database.asp

</div>
查看全部
weixin_33739523
weixin_33739523
2018/05/24 02:11
  • ajax
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信

2个回复