好的,所以我创建了一个 Javascript/PHP/Ajax 应用程序。我有一系列 6 个选择框。第一个是用 HTML 硬编码的。当您更改选择时,它会通过 Ajax 向 PHP 发送一个变量,PHP 使用该变量来查询数据库。当第二个框发生变化时,它会发送前一个选择框的 2 个变量。
每次更改选择框时,都会添加另一个要发送的变量。最后总共有 5 或 6 个变量,这一切都很好,一切都运行良好,几乎在做我想做的事情。
我的问题出现在选择框 3 和 6 上。
最初它们工作正常。但是当您返回更改选择框 2 时,数字 3 不会刷新。值与以前保持一致。与数字 6 相同,当我更改数字 3 时,框 4 会更改,并且按顺序框 5 会更改,但是框 6 仍与之前的查询相同。使用的所有 Ajax 代码都是相同的,只是变量名称和相关元素发生了变化。
有人可以帮忙吗?我将发布应用程序的链接和相关的 ajax 代码。
只是让您知道最初只有选择框 1 可见,其余的由 php/ajax onchange 生成。
这是有问题的代码
function getHTTPObject(){
if (window.ActiveXObject)
return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest)
return new XMLHttpRequest();
else {
alert("Your browser does not support AJAX.");
return null;
}
}
function doWork(){
var selectBox = document.getElementById("SelectManufacturer"); // get HTML select box by id
httpObject = getHTTPObject();
httpObject.open("GET", "http://4udev.refixstudios.co.uk/wp-content/martTest/bNbAjax.php?inputText="
+selectBox.options[selectBox.selectedIndex].text , true);
httpObject.onreadystatechange=function()
{
if (httpObject.readyState==4 && httpObject.status==200)
{
document.getElementById('selectModel').innerHTML = httpObject.responseText;;
}
}
httpObject.send()
}
function networkSelector()
{
var selectBox2 = document.getElementById("SelectManufacturer"); // get HTML select box by id
var selectModel = document.getElementById("modelSelector");
httpObject2 = getHTTPObject();
httpObject2.open("GET", "http://4udev.refixstudios.co.uk/wp-content/martTest/NetworkAjax.php?inputText2=" +selectBox2.options[selectBox2.selectedIndex].text +"&modelText2="+selectModel.options[selectModel.selectedIndex].text, true);
httpObject2.onreadystatechange = function()
{
if(httpObject2.readyState == 4 && httpObject2.status==200){
document.getElementById("networkSelect").innerHTML = httpObject2.responseText;
}
}
httpObject2.send();
}
function minuteSelector(){
var selectBox3 = document.getElementById("SelectManufacturer"); // get HTML select box by id
var selectModel3 = document.getElementById("modelSelector");
var NetworkSelect3 = document.getElementById("networkSelector");
httpObject3 = getHTTPObject();
httpObject3.open("GET", "http://4udev.refixstudios.co.uk/wp-content/martTest/minuteAjax.php?inputText3="+selectBox3.options[selectBox3.selectedIndex].text+"&modelText3="+selectModel3.options[selectModel3.selectedIndex].text+"&networkText3="+NetworkSelect3.options[NetworkSelect3.selectedIndex].text, true);
httpObject3.onreadystatechange = function(){
if(httpObject3.readyState == 4 && httpObject3.status==200){
document.getElementById("minuteSelect").innerHTML =httpObject3.responseText;
}
}
httpObject3.send();
}
function textSelector(){
var selectBox4 = document.getElementById("SelectManufacturer"); // get HTML select box by id
var selectModel4 = document.getElementById("modelSelector");
var networkSelect4 = document.getElementById("networkSelector");
var minuteSelect4 = document.getElementById("minutesSelector");
httpObject4 = getHTTPObject();
httpObject4.open("GET", "http://4udev.refixstudios.co.uk/wp-content/martTest/textAjax.php?inputText4=" +selectBox4.options[selectBox4.selectedIndex].text+"&modelText4="+selectModel4.options[selectModel4.selectedIndex].text+"&networkText4="+networkSelect4.options[networkSelect4.selectedIndex].text +"&minuteText4="+minuteSelect4.options[minuteSelect4.selectedIndex].text, true);
httpObject4.onreadystatechange = function(){
if(httpObject4.readyState == 4 && httpObject4.status==200){
document.getElementById("textSelect").innerHTML =httpObject4.responseText;
}
}
httpObject4.send();
}
function dataSelector(){
var selectBox5 = document.getElementById("SelectManufacturer"); // get HTML select box by id
var selectModel5 = document.getElementById("modelSelector");
var networkSelect5 = document.getElementById("networkSelector");
var minuteSelect5 = document.getElementById("minutesSelector");
var textsSelector5 = document.getElementById("textsSelector");
httpObject5 = getHTTPObjectAgainB();
httpObject5.open("GET", "http://4udev.refixstudios.co.uk/wp-content/martTest/dataAjax.php?inputText5="+selectBox5.options[selectBox5.selectedIndex].text+"&modelText5="+selectModel5.options[selectModel5.selectedIndex].text+"&networkText5="+networkSelect5.options[networkSelect5.selectedIndex].text +"&minuteText5="+minuteSelect5.options[minuteSelect5.selectedIndex].text+"&textText5="+textsSelector5.options[textsSelector5.selectedIndex].text, true);
httpObject5.onreadystatechange = function (){
if(httpObject5.readyState == 4){
document.getElementById("dataSelect").innerHTML = httpObject5.responseText;
}
}
httpObject5.send()
}
这是应用程序的链接http://4udev.refixstudios.co.uk/csv-test/
最好的测试方法是购买选择任何制造商和型号然后选择网络,然后选择Apple---The New Ipad 4G,这就是你注意到它没有变化的方式。此选择仅应将橙色带回网络
这是它调用的 PHP
<?php
if (isset($_GET['inputText2']))
{
$manufacturer = ($_GET['inputText2']);
if (isset ($_GET['modelText2']))
{
$model = ($_GET['modelText2']);
}
}
$conA = mysql_connect("localhost","****","*****");
if (!$conA)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("refixstu_4udev", $conA);
$selectApplea = mysql_query("SELECT DISTINCT network FROM wp_selector_apple WHERE model = '$model' ");
$selectBlackberry = mysql_query("SELECT DISTINCT network FROM wp_selector_blackberry WHERE model = '$model'");
$selectDoro = mysql_query("SELECT DISTINCT network FROM wp_selector_doro WHERE model = '$model'");
$selectHTC = mysql_query("SELECT DISTINCT network FROM wp_selector_htc WHERE model = '$model'");
$selectLG = mysql_query("SELECT DISTINCT network FROM wp_selector_lg WHERE model = '$model'");
$selectMotorola = mysql_query("SELECT DISTINCT network FROM wp_selector_motorola WHERE model = '$model'");
$selectNokia = mysql_query("SELECT DISTINCT network FROM wp_selector_nokia WHERE model = '$model'");
$selectSamsung = mysql_query("SELECT DISTINCT network FROM wp_selector_samsung WHERE model = '$model'");
$selectSony = mysql_query("SELECT DISTINCT network FROM wp_selector_sony WHERE model = '$model'");
$selectSonyE = mysql_query("SELECT DISTINCT network FROM wp_selector_sonyericsson WHERE model = '$model'");
$selectZte = mysql_query("SELECT DISTINCT network FROM wp_selector_ZTE WHERE model = '$model'");
?>
<select id="networkSelector" style="width:100px;" align="right" onchange="minuteSelector()">
<option> Select Network </option>
<?php
// Start Apple Testing
if($manufacturer == "Apple")
{
while($rowa = mysql_fetch_array($selectApplea))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "BlackBerry")
{
while($rowa = mysql_fetch_array($selectBlackberry))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "Doro")
{
while($rowa = mysql_fetch_array($selectDoro))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "HTC")
{
while($rowa = mysql_fetch_array($selectHTC))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "LG")
{
while($rowa = mysql_fetch_array($selectLG))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "Motorola")
{
while($rowa = mysql_fetch_array($selectMotorola))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "Nokia")
{
while($rowa = mysql_fetch_array($selectNokia))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "Samsung")
{
while($rowa = mysql_fetch_array($selectSamsung))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "Sony")
{
while($rowa = mysql_fetch_array($selectSony))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "Sone Ericsson")
{
while($rowa = mysql_fetch_array($selectSonyE))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
else if($manufacturer == "Zte")
{
while($rowa = mysql_fetch_array($selectLG))
{
foreach(array_unique($rowa) as $model)
{
echo"<option>"; echo $rowa['network']; echo"</option>";
}
}
}
mysql_close($conA);
?>
</select>