首先选择
<Select id="drop1" onchange="drop1(this.value)">
<option value ='1'>1</option
<option value ='2'>2</option
<option value ='3'>3</option
</select>
<div id = "txtHint1"></div>
选择值后,该值将发送到ajax。并在另一页上生成相应的下拉列表,并显示在div txthint1中。
第二次选择
<Select id="drop2" onchange="drop2(this.value)">
<option value ='111'>111</option
<option value ='222'>222</option
<option value ='333'>333</option
</select>
<div id = "txtHint2"></div>
由于生成的下拉列表是另一个php页面,如何获取用户选择在当前页面上显示的值(div txthint2)?
我将在php工作。
$value = $_GET['a'];
没有提交按钮。
答案 0 :(得分:2)
成功回复发出第二个请求:
function one() {
$.ajax({
...
success: function() {
two(TheValueFromOne);
}
});
}
function two() {
$.ajax({
...
});
}
正在发生的事情是,一旦请求成功完成,它就会立即自动启动下一个请求。
但是,如果你是jsut将值从一个页面传递给另一个页面,那么你真的不需要AJAX。
test1.php:
<form action="test2.php" method="get">
Book Title <br />
<input type="text" name="booktitle" /><br />
<input type="submit" name="submit" value=" - Update Database - " />
</form>
test2.php
<body>
<? echo $_GET["booktitle"]; ?>
</body>
test1.php:
<Select id="drop1" name="test1">
<option value ='1'>1</option
<option value ='2'>2</option
<option value ='3'>3</option
</select>
test2.php
<Select id="drop1">
<option selected = "<? echo $_POST['test1']; ?>"></option>
<option value ='1'>1</option
<option value ='2'>2</option
<option value ='3'>3</option
</select>
<div id = "txtHint2"><? echo $_POST['test1']; ?></div>
<form method="post" action="test2.php" >
<Select id="drop1" name="test1" onChange="this.parentNode.submit()">
<option value ='1'>1</option
<option value ='2'>2</option
<option value ='3'>3</option
</select>
</form>