abstract:<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Ajax中的$.get()</title></head><body><h3>江湖門派查詢系統(tǒng)$.get(
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Ajax中的$.get()</title>
</head>
<body>
<h3>江湖門派查詢系統(tǒng)$.get()</h3>
<label for="school">請選擇:</label>
<select name="school" id="school"></select>
<p id="detail"></p>
<script src="../lib/jquery.js"></script>
<script>
$.get('inc/school.php',function(data,status){
if (status === 'success') {
// $(data).appendTo('#school');
$('#school').html(data); // 另一種寫法
}
});
$('#school').change(function (event) {
// console.log($(this).serialize());
$.get(
'inc/detail.php', // 請求的url地址
{key: $(event.target).val()}, // 請求參數(shù),以對象字面量形式
function (data,status){ // 請求成功的回調(diào)方法
// console.log(status); // success
if (status === 'success') {
$('#detail').html(data);
$('[value=""]').remove();
} else { //出錯,未拿到響應(yīng)數(shù)據(jù)
$('#detail').html('<span style="color:red">請求錯誤</span>');
}
},
'html' // 響應(yīng)數(shù)據(jù)的格式,html/json/xml可省,會自動判斷
);
});
</script>
</body>
</html>
Correcting teacher:查無此人Correction time:2019-07-11 13:25:53
Teacher's summary:完成的不錯。三級聯(lián)動的效果有多種,都要學(xué)一些。繼續(xù)加油。