Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 表在搜索时未显示正确的值_Javascript_Jquery - Fatal编程技术网

Javascript 表在搜索时未显示正确的值

Javascript 表在搜索时未显示正确的值,javascript,jquery,Javascript,Jquery,我的代码没有显示正确的值 function showOffice(str) { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft

我的代码没有显示正确的值

function showOffice(str) {
      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 (xmlhttp.readyState==4 && xmlhttp.status==200) {
          document.getElementById("selectOffice").innerHTML=xmlhttp.responseText;
        }
      }
      xmlhttp.open("GET","officeData.php?office_id="+str,true);
      xmlhttp.send();
    }
这是我在演艺厅的职责

<table style="width: 100%;">
            <tr >
                <td><input style="width: 50%;"type="text" id="searchOffice" class="form-control" onkeypress="showOffice(this.value)"  placeholder="Search Office..."></td>
            </tr>
            </table>

    <div id="selectOffice"></div>

我将为此使用jquery。选择Office table位于不同的文件中


如果我的代码或问题不充分,请给我留言,我将发送文件。非常感谢

我认为您需要将响应文本设置为文本框的值


document.getElementById(“selectOffice”).value=xmlhttp.responseText

您希望它显示什么值以及它当前显示什么值?如果您使用jQuery,那么有更简单的方法来发出ajax请求。您也可以考虑使用<代码>控制台.log(XMLHTTP.ReaveStEXT)来查看正在返回什么数据,以确保它是您所期望的。