JQuery中ajax和JSON的獲取
1.getJSON
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>使用getJSON()方法非同步載入JSON格式資料</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
</head>
<body>
<div id="divtest">
<div class="title">
<span class="fl">我最喜歡的一項運動</span>
<span class="fr">
<input id="btnShow" type="button" value="get" />
</span>
</div>
<ul></ul>
</div>
<script type="text/javascript">
$(function () {
$("#btnShow").bind("click", function () {
var $this = $(this);
$.getJSON("http://localhost:8080/news/ShowNewsService", function (data){
$this.attr("disabled", "false");
$.each(data, function (key, dataList) {
for(var i=0; i<dataList.length; i++)
$("ul").append("<li>" + dataList[i].newsUrl + "</li>");
});
});
});
});
</script>
</body>
</html>
2.Ajax方式非同步獲取伺服器資料
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>使用ajax()方法載入伺服器資料</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="divtest">
<div class="title">
<span class="fl">檢測數字的奇偶性</span>
<span class="fr">
<input id="btnCheck" type="button" value="檢測" />
</span>
</div>
<ul>
<li>請求輸入一個數字
<input id="txtNumber" type="text" size="12" />
</li>
</ul>
</div>
<script type="text/javascript">
$(function () {
$("#btnCheck").bind("click", function () {
$.ajax({
url: "http://www.imooc.com/data/check.php",
data: { num: $("#txtNumber").val() },
type: "post",
success: function (data) {
$("ul").append("<li>你輸入的<b> "
+ $("#txtNumber").val() + " </b>是<b> "
+ data + " </b></li>");
}
});
})
});
</script>
</body>
</html>
3.參考
http://blog.csdn.net/smartsmile2012/article/details/17316351
相關文章
- jQuery : ajax獲取Status CodejQuery
- jquery實現的ajax請求獲取json資料程式碼jQueryJSON
- jQuery的ajax和json使用例項jQueryJSON
- 如何用jquery獲取DIV中的TR和TDjQuery
- jquery簡單ajax示例_讀取json檔案資料jQueryJSON
- 通過JQuery ajax獲取伺服器時間jQuery伺服器
- jQuery、ajax新增Json資料jQueryJSON
- JQuery 獲取select被選中的value和textjQuery
- jQuery如何獲取iframe中的元素jQuery
- jquery獲取json資料簡單介紹jQueryJSON
- jQuery ajax清除快取jQuery快取
- jquery獲取ajax傳遞的值一個需要注意的地方jQuery
- jquery和bootstrap獲取checkbox選中的多行資料jQueryboot
- ajax設定contentType=json後臺獲取不到引數JSON
- jQuery獲取表格的指定行和列jQuery
- jquery 設定checkbox選中 和獲取選中值jQuery
- 在JQuery中,$.ajax() 的用法jQuery
- ajax和json物件JSON物件
- Jquery獲取css中id和class樣式的動作-#id和.classjQueryCSS
- jquery獲取checkbox是否選中jQuery
- 介面測試之 json 中的 key 獲取JSON
- 介面測試之json中的key獲取JSON
- JAVA獲取json中的全部鍵值對JavaJSON
- JQuery中ajax的使用與快取問題的解決方法jQuery快取
- jQuery ajax中success和complete區別jQuery
- jQuery - 獲取內容和屬性jQuery
- jquery設定和獲取元素的屬性jQuery
- jQuery如何獲取元素的寬度和高度jQuery
- iframe的操作-Js/Jquery獲取iframe中的元素JSjQuery
- jquery獲取選中checkbox核取方塊的值jQuery
- jquery ajax請教的快取問題jQuery快取
- jQuery獲取選中的checkbox核取方塊的值jQuery
- Jquery 和 Ajax的 使用方法jQuery
- jquery獲取沒有選中的checkbox核取方塊jQuery
- jQuery的AJAX請求中contentType和dataType的區別jQuery
- jQuery捕獲-獲取DOM元素內容和屬性jQuery
- JQuery獲取input type=jQuery
- jquery獲取子元素jQuery