[英]select option tag does not change using ajax/php call?
以下代碼嘗試通過進行Ajax調用來更改Select選項標簽,該調用連接到服務器上的PHP並檢索數據。 但是,如果我將響應文本設置為span標記,則以下代碼可以正常工作,但不適用於Select option標記?
<?php
$q = intval($_GET['q']);
$con=mysqli_connect("localhost","rot","ro","abc","3306");
/
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT DISTINCT(UniqueBusId) FROM cfv_busstopnames WHERE busnumber = ".$q." ");
if (!$result) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
while($row = mysqli_fetch_array($result))
{
echo "<option>" . $row['UniqueBusId'] . "</option>" ;
}
mysqli_close($con);
?>
。
<script>
function showUser(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 (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("select-choice-direction").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getdirection.php?q="+str.value,true);
xmlhttp.send();
}
</script>
<Body>
<label for="select-choice-direction">Direction</label>
<select name="select-choice-direction" id="select-choice-direction" data-native-menu="false" ">
<option> Direction heading towards?</option>
<option value="X">X</option>
<option value="Y">Y</option>
<!-- etc. -->
</select>
</Body>
代替
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("select-choice-direction").innerHTML=xmlhttp.responseText;
}
}
嘗試
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
$('#select-choice-direction').html(xmlhttp.responseText).selectmenu( "refresh");
}
}
這告訴jQuery Mobile刷新selectmenu小部件( http://api.jquerymobile.com/selectmenu/#method-refresh )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.