ajax
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax</title>
<style type="text/css">
</style>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$.ajax({
url: 'data.json',//請(qǐng)求的服務(wù)器路徑,實(shí)際開發(fā)中寫文檔接口的路徑
type: 'get',//分get/post請(qǐng)求
dataType: 'json',//要讀取什么格式的數(shù)據(jù),xml script html upload
// data:{page:1}//請(qǐng)求時(shí)要攜帶的參數(shù)
})
.done(function(data){//成功的時(shí)候會(huì)執(zhí)行的函數(shù)
alert(data.name);
console.log(data);
})
.fail(function(){//失敗的時(shí)候
console.log("error");
})
/*.always(function(){//不論成功與否都會(huì)執(zhí)行
console.log("always");
})*/;
</script>
</head>
<body>
</body>
</html>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。