AJAX返回的结果加上整个页面内容(使用Javascript、PHP、MySQL但不使用JQuery)

AJAX返回的结果加上整个页面内容(使用Javascript、PHP、MySQL但不使用JQuery),javascript,mysql,ajax,select,drop-down-menu,Javascript,Mysql,Ajax,Select,Drop Down Menu,我在我的网站上运行了一个AJAX脚本,它应该在发生上一个下拉菜单更改事件后更新一个相关的下拉菜单(选择选项菜单) 当我单击第一个下拉列表时,第二个下拉列表似乎填充了来自MySQL数据库查询的正确值。然而,在我的价值观下,我似乎也将整个HTML网页上的内容作为一个整体拉进去 我想知道如何只输入我的值,而不在我的选择选项菜单中再次加载整个网页 我的Javascript: <script type="text/javascript"> function showUser(str) { if

我在我的网站上运行了一个AJAX脚本,它应该在发生上一个下拉菜单更改事件后更新一个相关的下拉菜单(选择选项菜单)

当我单击第一个下拉列表时,第二个下拉列表似乎填充了来自MySQL数据库查询的正确值。然而,在我的价值观下,我似乎也将整个HTML网页上的内容作为一个整体拉进去

我想知道如何只输入我的值,而不在我的选择选项菜单中再次加载整个网页

我的Javascript:

<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp_aris=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp_aris=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp_aris.onreadystatechange=function()
  {
  if (xmlhttp_aris.readyState==4 && xmlhttp_aris.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp_aris.responseText;
    }
  }
xmlhttp_aris.open('GET','http://mywebdomain.com?ajax=true&q='+str,true);
xmlhttp_aris.send();
}
</script>

函数showUser(str)
{
如果(str==“”)
{
document.getElementById(“txtHint”).innerHTML=“”;
返回;
} 
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp_aris=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp_aris=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp_aris.onreadystatechange=函数()
{
if(xmlhttp_aris.readyState==4&&xmlhttp_aris.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp_aris.responseText;
}
}
xmlhttp_aris.open('GET','http://mywebdomain.com?ajax=true&q=“+str,对);
xmlhttp_aris.send();
}
我的PHP代码:

   // begin my ghetto code
    if ($_GET['ajax'] == 'true') {

     $q = $_REQUEST["q"];


$con = mysqli_connect('localhost','db_user','db_pass','db_name');
if (!$con)
  {
  die('Could not connect: ' . mysqli_error($con));
  }



$sql='SELECT DISTINCT
employees.firstName,
employees.lastName
FROM
sales_reps
INNER JOIN employees ON sales_reps.employeeId = employees.employeeId
INNER JOIN sales_campaign ON sales_campaign.salesCampId = sales_reps.saleCampId
WHERE
sales_campaign.marketId = '.$q.' AND
employees.isactive = 1';

$result = mysqli_query($con,$sql);

while($row = mysqli_fetch_array($result))
  {
  echo '<option value="' . $row['firstName'] . '">'
            . htmlentities($row['firstName']) .' '.htmlentities($row['lastName']) .'</option>';
  }
mysqli_close($con);
}
// end my ghetto code
//开始我的贫民区代码
如果($\u GET['ajax']=='true'){
$q=$_请求[“q”];
$con=mysqli_connect('localhost','db_user','db_pass','db_name');
如果(!$con)
{
die('无法连接:'。mysqli_错误($con));
}
$sql='SELECT DISTINCT
雇员的名字,
employees.lastName
从…起
销售代表
内部加入销售代表上的员工。\u reps.employeeId=employees.employeeId
内部加入sales\u campaign ON sales\u campaign.salesCampId=sales\u reps.saleCampId
哪里
sales_campaign.marketId=“.$q.”和
employees.isactive=1';
$result=mysqli\u查询($con,$sql);
while($row=mysqli\u fetch\u数组($result))
{
回声“
.htmlentities($row['firstName'])。'.htmlentities($row['lastName'])。';
}
mysqli_close($con);
}
//结束我的犹太区代码
带有下拉菜单的页面上的我的代码:

<select id="frm-marketid" name="frm-marketid" onchange="showUser(this.value)">
<option value="">Choose a Market</option>
<option value="74">Annapolis</option>
<option value="61">Anne Arundel</option>
<option value="26">Aventura</option>
<option value="63">Baltimore</option>
</select>
<br/>     

<select id="txtHint"><b>Person info will be listed here.</b></select>  

选择市场
安纳波利斯
安娜兰多
阿文图拉
巴尔的摩

此处将列出人员信息。
在输出对ajax的响应后,只需终止脚本即可

...  
  }
  mysqli_close($con);
  exit;
}
...

穆萨,非常感谢你,这非常令人振奋。我们将永远感激你的帮助!