【发布时间】:2022-11-18 01:14:51
【问题描述】:
这是 HTML 中的选择和选项。我在这里使用 jquery。我需要获取两个 select 的值并将值传递给 ajax.php,我需要在其中使用这两个值来检查我的数据库并继续进行另一个相关的下拉列表。
<label>Select Number: </label>
<select id= "number" onchange="FetchState(this.value)" required>
<option value="0">-- 0 --</option>
<option value="1">-- 1 --</option>
<option value="2">-- 2 --</option>
<option value="3">-- 3 --</option>
</select>
<label>Select letter: </label>
<select id="alphabet" required>
<option value="a">-- a --</option>
<option value="b">-- b --</option>
<option value="c">-- c --</option>
<option value="d">-- d --</option>
</select>
<select id="dependent">
</select>
这是我下面写的脚本代码。
function FetchState(id) {
$("#dependent").html('');
$.ajax({
type: "POST",
url: "ajax.php",
data: {
number: id,
},
success: function(data) {
$("#dependent").html(data);
}
});
}
</script>
我需要通过 jquery(ajax) 将两个值传递给 PHP 才能继续。这里字母和字母值都应该被获取并作为 jquery 中的数据传递给 ajax.php
【问题讨论】:
-
因此,您知道另一个下拉列表的
id,首先检查某些内容是否已选中,然后获取所选项目的 .val。如果您只是启动一两个 DuckDuck 搜索,那么实际上必须有 1000 个示例 -
获取值很好,但是如何在 jquery 中一次将两个值实际传递给 ajax.php
-
data: { number: id,alpha: alp },
标签: javascript php jquery ajax