jquery学习笔记 ajaxStart ajaxStop
2013-04-02 17:59
429 查看
<!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 runat="server">
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
* { margin:0; padding:0;}
body { font-size:12px;}
.comment { margin-top:10px; padding:10px; border:1px solid #ccc;background:#DDD;}
.comment h6 { font-weight:700; font-size:14px;}
.para { margin-top:5px; text-indent:2em;background:#DDD;}
</style>
<!-- 引入jQuery -->
<script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script>
<script>
$(function(){
$('#send').click(function() {
$.ajax({
type: "GET",
url: "test.js",
dataType: "script"
});
});
//共用这2个全局的ajax事件
$("#loading").ajaxStart(function(){
$(this).show();
});
$("#loading").ajaxStop(function(){
$(this).hide();
}); //ajaxStart ajaxStop 好处 :在请求的过程中阻止用户操作,比如可以在ajax请求的过程中进行一些遮罩,
})
</script>
</head>
<body>
<div id="loading">加载中...</div>
<br/>
<p>
<input type="button" id="send" value="加载"/>
</p>
<div class="comment">已有评论:</div>
<div id="resText" >
</div>
</body>
</html>
test.js
var comments = [
{
"username": "张三",
"content": "沙发."
},
{
"username": "李四",
"content": "板凳."
},
{
"username": "王五",
"content": "地板."
}
];
var html = '';
$.each( comments , function(commentIndex, comment) {
html += '<div class="comment"><h6>' + comment['username'] + ':</h6><p class="para">' + comment['content'] + '</p></div>';
})
$('#resText').html(html);
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
* { margin:0; padding:0;}
body { font-size:12px;}
.comment { margin-top:10px; padding:10px; border:1px solid #ccc;background:#DDD;}
.comment h6 { font-weight:700; font-size:14px;}
.para { margin-top:5px; text-indent:2em;background:#DDD;}
</style>
<!-- 引入jQuery -->
<script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script>
<script>
$(function(){
$('#send').click(function() {
$.ajax({
type: "GET",
url: "test.js",
dataType: "script"
});
});
//共用这2个全局的ajax事件
$("#loading").ajaxStart(function(){
$(this).show();
});
$("#loading").ajaxStop(function(){
$(this).hide();
}); //ajaxStart ajaxStop 好处 :在请求的过程中阻止用户操作,比如可以在ajax请求的过程中进行一些遮罩,
})
</script>
</head>
<body>
<div id="loading">加载中...</div>
<br/>
<p>
<input type="button" id="send" value="加载"/>
</p>
<div class="comment">已有评论:</div>
<div id="resText" >
</div>
</body>
</html>
test.js
var comments = [
{
"username": "张三",
"content": "沙发."
},
{
"username": "李四",
"content": "板凳."
},
{
"username": "王五",
"content": "地板."
}
];
var html = '';
$.each( comments , function(commentIndex, comment) {
html += '<div class="comment"><h6>' + comment['username'] + ':</h6><p class="para">' + comment['content'] + '</p></div>';
})
$('#resText').html(html);
相关文章推荐
- 【jQuery学习笔记】关于jQuery1.6.1版的ajaxstart不执行问题解决方案
- jQuery学习——ajax的ajaxStart()与ajaxStop()方法
- learning jQuery 学习笔记十五(+jQuery 1.4.1 API)-- AJAX----load(url, [data], [callback])
- MVC学习笔记之使用JQuery方式发送Ajax请求调用后台Controller
- js中的ajax和jquery中的ajax学习笔记
- jquery中ajax学习笔记一
- web学习笔记22-jQuery学习-2(post ajax)
- 【jQuery学习笔记--------AJAX之jQuery角度分析】
- jQuery学习笔记(Ajax)
- jQuery学习笔记 — jQuery 与 Ajax 的应用
- learning jQuery 学习笔记十六(+jQuery 1.4.1 API)-- AJAX----$.get() & $.post()
- 学习笔记:关于Firefox中jQuery.ajax()返回Xml Document
- 20151209jquery学习笔记Ajax 代码备份
- ajax(jQuery)学习笔记
- jQuery学习笔记:Ajax(一)
- ROS进二阶学习笔记(3) - programmatic way to start/stop a roslaunch
- jquery学习笔记----ajax使用
- 黑马程序员之 ASP.NET学习笔记:jquery+ajax无刷新分页代码
- jQuery学习笔记四(jQuery - AJAX)
- jQuery学习笔记之Ajax用法详解