我向我的网站添加了一个脚本,该脚本生成了一个链式选择系统。它工作正常,但是当我尝试将数据提取到我的搜索脚本中时,我意识到它不会生成任何我可以使用的源代码。我附上我认为能够解决此问题的重要部分。请在降级之前告诉我。谢谢!
<script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#judet').change(function(){
$('#wait_1').show();
$('#result_1').hide();
$.get("func.php", {
func: "judet",
drop_var: $('#judet').val()
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
});
return false;
});
});
function finishAjax(id, response) {
$('#wait_1').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
HTML部分:
<tr>
<td><label>Judet</label></td>
<td><select name="judet" id="judet">
<option value="" selected="selected" disabled="disabled">Selecteaza judetul</option>
<?php getTierOne(); ?>
</select></td>
<tr>
<td><label>Localitate</label></td>
<td>
<span id="wait_1" style="display: none;"><img alt="Asteptati..." src="images/ajax-loader.gif"/></span>
<span id="result_1" style="display: none;"></span>
</td>
</tr>
PHP部分:
function judet($drop_var)
{
include_once('mysql_connect.php');
$result = mysql_query("SELECT * FROM orase WHERE judet='$drop_var'")
or die(mysql_error());
echo '<select name="tier_two" id="tier_two">
<option value=" " disabled="disabled" selected="selected">Selecteaza localitatea</option>';
while($drop_2 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_2['oras'].'">'.$drop_2['oras'].'</option>';
}
echo '</select>';
}