本文实例讲述了jQuery中ajax的get()方法用法。分享给大家供大家参考。具体分析如下:
$.get()通过 HTTP GET请求从服务器上请求数据。
语法结构:
$.get(url, [data], [callback], [type]);
参数解析:
1.URL:必须,规定请求的URL。
2.data:可选,待发送 Key/value 参数。
3.callback:可选,请求成功后所执行的回调函数。
4.type:可选,返回内容格式,xml, html, script, json, text, _default。
代码实例:
<!DOCTYPE html>
<html>
<head>
<meta charset=\"utf-8\">
<meta name=\"author\" content=\"http://www.phpstudy.net/\" />
<title>phpstudy</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程序设计有所帮助。
本文地址:https://www.stayed.cn/item/14156
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我