我用select方法处理ajax请求的问题吗?

时间:2019-05-18 16:32:32

标签: javascript php ajax xmlhttprequest

仅在使用时出现错误,但是如果我删除,则选择的代码工作正常。

 function adv1(str) {
  if (str=="") {
    document.getElementById("txtHint").innerHTML="";
    return;
  } 
  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("adv1").innerHTML=this.responseText;
    }
  }
  xmlhttp.open("GET","ajax/getoffer.php?q="+str,true);
  xmlhttp.send();
}
</script>
 <select class="form-control"  >
<p id="adv1"></p>
</select>
<?php
require_once('../../global.php');

$q = intval($_GET['q']);
$errors = array();
$query = mysql_query("SELECT * FROM `offer` WHERE adv_id = '".$q."'");
if (mysql_num_rows($query) > 0)
{
    while ($row = mysql_fetch_array($query))
   {

    echo'<option value="'.$row['id'].'">'.$row['offer_name'].'</option>';

   }
}

未捕获的TypeError:无法将属性'innerHTML'设置为null     在XMLHttpRequest.xmlhttp.onreadystatechange

0 个答案:

没有答案