php - 通过ajax获取Select标签值

标签 php jquery mysql ajax

<?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/

相关文章:

PHP 的配置设置 'error_log' 不起作用

JQuery 表单提交添加请求 header

php - 在循环内运行 MySQL 查询

java - com.mysql.jdbc.MysqlDataTruncation : Data truncation: Data too long for column 'DATE' at row 1

jquery - 弹出框没有像它们应该的那样居中

java - 如何使用 Hibernate 将 UUID 作为主键在两个表中共享?

php - 我如何找出哪个用户正在运行当前的 php 脚本?

php - 如何使用 javascript 回显 php 变量?

php - Laravel : Email Jobs are not attempted

Javascript Count 在文本框中重复相同值的次数