本文實例講述了jQuery中ajax的get()方法用法。分享給大家供大家參考。具體分析如下:
$.get()通過 HTTP GET請求從服務(wù)器上請求數(shù)據(jù)。
語法結(jié)構(gòu):
$.get(url, [data], [callback], [type]);
參數(shù)解析:
1.URL:必須,規(guī)定請求的URL。
2.data:可選,待發(fā)送 Key/value 參數(shù)。
3.callback:可選,請求成功后所執(zhí)行的回調(diào)函數(shù)。
4.type:可選,返回內(nèi)容格式,xml, html, script, json, text, _default。
代碼實例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://m.survivalescaperooms.com/" />
<title>武林網(wǎng)</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#bt").click(function(){
$.get("mytest/demo/antzone.txt",function(data,status){
alert("Data:"+data+"/nStatus:"+status);
})
})
})
</script>
</head>
<body>
<input type="button" value="查看效果" id="bt"/>
</body>
</html>
希望本文所述對大家的jQuery程序設(shè)計有所幫助。