填充雖然我敢肯定,這一定有什麼真的很明顯,我看不到我要去的地方錯。我有一個下拉列表,其中有兩個選項。當我選擇一個選項時,它應該使用XMLHttpRequest()根據選擇的選項從數據庫中獲取客戶列表。下拉列表中不使用Ajax
我有兩個部分:
ajax2_js.php - 包含JavaScript和HTML的形式。
ajax2_DBAccess.php - 包含從DATABSE獲取列表中的PHP。
我已經檢查了第二頁上的所有內容,並能正常工作在它自己的(並顯示相關列表作爲下拉菜單),但是當我選擇第一頁上的選項,沒有任何反應。
我的代碼到目前爲止是:
ajax2_js.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function ajaxFunction()
{
var ajaxRequest;
ajaxRequest = new XMLHttpRequest();
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4)
{
document.getElementById('customerDiv').innerHTML=req.responseText;
}
}
ajaxResuest.open("GET", strURL, true);
ajaxRequest.send(null);
}
</script>
</head>
<body>
<form method="post" action="" name="form1">
Network : <select name="network" onChange="ajaxFunction('ajax2_DBAccess.php?network='+this.value)">
<option value="">Select Network</option>
<option value="1">Net1</option>
<option value="2">Net2</option>
</select>
</br>
Customer : <div id="customerDiv">
<select name="select">
<option>Select Customer</option>
</select>
</div>
</form>
</body>
ajax2_DBAccess.php
<?php
$network=$_GET['network'];
$q1 = "SELECT `CustName` FROM monitor.customers where network = $network;";
$con = new mysqli('localhost:3306', 'xxx', 'xxx');
if (mysqli_connect_errno())
{
$error = mysqli_connect_error();
echo $error;
exit();
}
else
{
$ConfRes = mysqli_query($con, $q1);
if ($ConfRes)
{
echo "<select name=\"Customers\">";
echo "<option>Select Customer</option>";
while($row=mysqli_fetch_array($ConfRes, MYSQLI_ASSOC))
{
$result = $row['CustName'];
echo "<option value>$result</option>";
};
echo "</select>";
}
else
{
$error = mysqli_error();
echo $error;
exit();
}
};
?>
任何援助將不勝感激。
'ajaxFunction'中'strURL'的值是什麼? – wroniasty