Javascript 如何使用jQueryAjax和php制作3个相关组合
好的,这就是我到目前为止的情况 第一页获取数据并填充第一个组合框,这里没有问题, 然后用户从combo1中选择一个值,并使用ajax创建第二个combobox,其中包含过滤后的数据。这里也行! 问题是,我需要使用combo2.change属性触发另一个ajax请求以显示最终数据。 我的问题是我对这个不够熟悉,无法创建最后一个请求…我不知道如何做 这是我在index.php上的代码,它在处理call21.php中的数据后正确加载了第二个组合…此时,我在call21.php中没有脚本,只有获取所需值的数据库代码,将其发送回index.php页面中的div并创建组合框。 当classe=drop2时Javascript 如何使用jQueryAjax和php制作3个相关组合,javascript,php,jquery,ajax,combobox,Javascript,Php,Jquery,Ajax,Combobox,好的,这就是我到目前为止的情况 第一页获取数据并填充第一个组合框,这里没有问题, 然后用户从combo1中选择一个值,并使用ajax创建第二个combobox,其中包含过滤后的数据。这里也行! 问题是,我需要使用combo2.change属性触发另一个ajax请求以显示最终数据。 我的问题是我对这个不够熟悉,无法创建最后一个请求…我不知道如何做 这是我在index.php上的代码,它在处理call21.php中的数据后正确加载了第二个组合…此时,我在call21.php中没有脚本,只有获取所需值
<script type="text/javascript">
$(document).ready(function(){
$(document).ajaxStart(function(){
$("#wait").css("display","block");
});
$(document).ajaxComplete(function(){
$("#wait").css("display","none");
});
$(".drop1").change(function(){
var id=$(this).val();
var dataString = 'user='+ id;
$.ajax({
type: "POST",
url: "call21.php",
data: dataString,
cache: false,
success: function(html){
$(".tab2").html(html);
$(".tab1").text(id);
}});
});
});
</script>
我的问题是,我必须把代码放在哪里才能进行第二次ajax调用???index.php还是call21.php???
你们能帮我弄一下密码吗
我有超过100小时的谷歌在这个问题上,但我的知识,这只是太短,以找到一个解决方案,我自己 这是一个基本示例
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo for 3 Ajax Form</title>
<script src='jquery.min.js'></script>
<script>
$(function(){
$(".select:not(:first)").hide();//Hide All Expect First
//fill up first
$.get("index.php?select=1",function(data){
$("#first").html(data);
}); //
//
$("#first").change(function(){
$.get("index.php?select=2&value="+$("#first").val(),function(data){
$("#second").html(data);
});
$("#second").show();
});
$("#second").change(function(){
$.get("index.php?select=3&value="+$("#second").val(),function(data){
$("#third").html(data);
});
$("#third").show();
});
})
</script>
</head>
<body>
<select class="select" id="first"></select>
<select class="select" id="second"></select>
<select class="select" id="third"></select>
</body>
</html>
和index.php
<?php
$list_for_first = array("a" , "b" , "c");
$list_for_second = array(array("aa","aa") , array("bb","bb") , array("cc","cc"));
$list_for_third = array(array("aaa","aaa","aaa") , array("bbb","bbb","bbb") , array("ccc","ccc","ccc"));
switch ($_GET['select']) {
case 1:
foreach ($list_for_first as $key => $value) {
echo "<option value='$key'>$value</option>";
}
break;
case 2:
$selected = $_GET['value'];
foreach ($list_for_second[$selected] as $key => $value) {
echo "<option value='$key'>$value</option>";
}
break;
case 3:
$selected = $_GET['value'];
foreach ($list_for_third[$selected] as $key => $value) {
echo "<option value='$key'>$value</option>";
}
break;
}
?>
每个选择有3个数组。然后,如果更改first或second index.php,则按所选选项值返回“options”。该值显示子数组的此代码中的索引$key。例如,当从第一个字符串中选择b时,查询字符串可以类似于'index.php?selected=2&value=1'。另一方面,当从第二个数组中选择cc时,查询字符串应为'index.php?selected=3&value=2',index.php将返回第三个数组中列表的第三个子数组。祝你今天愉快