<?php
include('connection.php');
$query="select * from category";
$result=mysql_query($query,$conn);
echo'
<select name="category" id="uni" >';
//The select tag start here,It gets options from Database
while($catrow=mysql_fetch_array($result)) {
echo'<option value="">';
echo'<option value="'.$catrow['Id'].'">'.$catrow['Name'].
'</option></form>';
}
echo'</select>';
?><br />
现在我有这样的ajax代码,我知道如何使用ajax获取输入值,但我不知道如何使用ajax获取选择标签值。
我将这行代码用于输入类型:
function checkUser() {
var str=document.form.category.value;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request");
return;
}
//this line is where I get inputs value,how can I get Select tag's?????!!!
url='addserv.phptitle='+document.getElementById('title').value+document.getElementById('latitude').value+document.getElementById('ownerId').value;
//alert(url);
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged() {
if (xmlHttp.readyState==4 ){
var name = xmlHttp.responseText;
}
}
最佳答案
如果您的 PHP 回显了正确的标记并且您想将其附加到 DOM,那么您可以执行以下操作:
$.ajax({
type: 'GET',
url: 'something.php',
success: function(data) {
$('.someElement').html(data);
}
});
关于php - 通过ajax获取Select标签值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24517043/