在其他select ajax php上进行更改时显示select
我有一个代码,我不知道我的问题是什么。 我正在尝试从其他选择打开另一个选择,并在新选择选项中获取旧的选择值,但我不能这样做,我不知道为什么。 这是我的代码,我的页面我在其中编写了名为mekha.php的代码:在其他select ajax php上进行更改时显示select,php,ajax,select,Php,Ajax,Select,我有一个代码,我不知道我的问题是什么。 我正在尝试从其他选择打开另一个选择,并在新选择选项中获取旧的选择值,但我不能这样做,我不知道为什么。 这是我的代码,我的页面我在其中编写了名为mekha.php的代码: <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script type="te
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function showUser(str) {
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("makhfe").style.display = "block";
}
}
xmlhttp.open("GET","mekha.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
if(isset($_GET["q"]))
{
echo $_GET["q"];
}
?>
<select id="firstselect" onchange="showUser(this.value)">
<option value="1">One</option>
<option value="2">Two</option>
</select>
<select style="display:none;" id="makhfe">
<option value="1">One</option>
<option value="2"><?=intval($_GET["q"])?></option>
</select>
</body>
</html>
有什么帮助吗?类似的方法应该可以:
$("#firstselect").change(function() {
value = $("#firstselect").val();
data = {"value": value };
$.post("server_ajax_link.php", data)
.done(function(data) {
new_data = data.new_value_from_server;
});
$("#makhfe").show();
$("#makhfe[value='2']").text(new_data );
});
有关更简单的示例,请查看此处的文档:谢谢。。。但是我需要更改php变量并在sql查询中使用它..我对select选项做了更改只是为了看看它是否工作..但实际上我需要更改php变量您可以在服务端文件中执行,然后查询您想要的,然后使用通过ajax返回的结果。如果这些不是你想要的,请解释更多。当我改变第一个选择时,我需要…在post中获取他的值或通过ajax获取。这就是代码所做的。value=$firstselect.val;数据={value:value};这些行从第一个选择中获取值。这些行$.postserver\u ajax\u link.php,data.donefunctiondata{new\u data=data.new\u value\u from\u server;};将其发送到服务器并从服务器获取您想要的任何内容。这些行$makhfe.show$makhfe[value='2'].textnew_数据;将来自服务器的新数据放置在第二个选择框中。我错过了什么?你能提供一个链接和服务器端脚本吗