使用Ajax和Jquery实现GridView的展开、合并
2009-09-06 20:30
746 查看
需求简介:[/b]电子商务网站中,查询会员的订单,点击“會員”,展现此会员的订单列表。Demo
界面操作:[/b]
Step 1 展现会员列表,如下图
function showhide(master,detail,customerId)
{
//First child of master div is the image
var src = $(master).children()[0].src;
//Switch image from (+) to (-) or vice versa.
if(src.endsWith("plus.png"))
src = src.replace('plus.png','minus.png');
else
src = src.replace('minus.png','plus.png');
//if the detail DIV is empty Initiate AJAX Call, if not that means DIV already populated with data
if($(detail).html() == "")
{
//Prepare Progress Image
var $offset = $(master).offset();
$('#progress').css('visibility','visible');
$('#progress').css('top',$offset.top);
$('#progress').css('left',$offset.left+$(master).width());
//Prepare Parameters
var params = '{customerId:"'+ customerId +'"}';
//Issue AJAX Call
$.ajax({
type: "POST", //POST
url: "GridViewDrillDownjQueryAjax.aspx/GetOrders", //Set call to Page Method
data: params, // Set Method Params
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");},
contentType: "application/json; charset=utf-8", //Set Content-Type
dataType: "json", // Set return Data Type
success: function(msg, status) {
$('#progress').css('visibility','hidden');
$(master).children()[0].src = src;
$(detail).html(msg);
$(detail).slideToggle("normal"); // Succes Callback
},
error: function(xhr,msg,e){
alert(msg);//Error Callback
}
});
}
else
{
//Toggle expand/collapse
$(detail).slideToggle("normal");
$(master).children()[0].src = src;
}
}
解释:
type: 请求方式使用“post”
url: 请求的URL
data: 要传的参数
beforeSend:请求发送之前所要做的操作
contentType: 设置contentType为application/json; charset=utf-8
datatype: 设置返回类型为 json
success:请求成功返回正确的结果后 所要操作的事情,比如向第二个div追加订单列表html代码,然后滑动展示。
Error: 请求失败,弹出失败信息
至此,使用Ajax和Jquery实现GridView的展开和合并完毕。
源代码下载:http://files.cnblogs.com/ywqu/GridViewDrillDownJQueryAjax.rar
英文地址:http://mosesofegypt.net/post/GridView-Grouping-Master-Detail-Drill-Down-Using-jQuery-AJAX.aspx
界面操作:[/b]
Step 1 展现会员列表,如下图
function showhide(master,detail,customerId)
{
//First child of master div is the image
var src = $(master).children()[0].src;
//Switch image from (+) to (-) or vice versa.
if(src.endsWith("plus.png"))
src = src.replace('plus.png','minus.png');
else
src = src.replace('minus.png','plus.png');
//if the detail DIV is empty Initiate AJAX Call, if not that means DIV already populated with data
if($(detail).html() == "")
{
//Prepare Progress Image
var $offset = $(master).offset();
$('#progress').css('visibility','visible');
$('#progress').css('top',$offset.top);
$('#progress').css('left',$offset.left+$(master).width());
//Prepare Parameters
var params = '{customerId:"'+ customerId +'"}';
//Issue AJAX Call
$.ajax({
type: "POST", //POST
url: "GridViewDrillDownjQueryAjax.aspx/GetOrders", //Set call to Page Method
data: params, // Set Method Params
beforeSend: function(xhr) {
xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");},
contentType: "application/json; charset=utf-8", //Set Content-Type
dataType: "json", // Set return Data Type
success: function(msg, status) {
$('#progress').css('visibility','hidden');
$(master).children()[0].src = src;
$(detail).html(msg);
$(detail).slideToggle("normal"); // Succes Callback
},
error: function(xhr,msg,e){
alert(msg);//Error Callback
}
});
}
else
{
//Toggle expand/collapse
$(detail).slideToggle("normal");
$(master).children()[0].src = src;
}
}
解释:
type: 请求方式使用“post”
url: 请求的URL
data: 要传的参数
beforeSend:请求发送之前所要做的操作
contentType: 设置contentType为application/json; charset=utf-8
datatype: 设置返回类型为 json
success:请求成功返回正确的结果后 所要操作的事情,比如向第二个div追加订单列表html代码,然后滑动展示。
Error: 请求失败,弹出失败信息
至此,使用Ajax和Jquery实现GridView的展开和合并完毕。
源代码下载:http://files.cnblogs.com/ywqu/GridViewDrillDownJQueryAjax.rar
英文地址:http://mosesofegypt.net/post/GridView-Grouping-Master-Detail-Drill-Down-Using-jQuery-AJAX.aspx
相关文章推荐
- 艾伟_转载:使用Ajax和jQuery实现GridView的展开、合并
- 使用Ajax和Jquery实现GridView的展开、合并
- 使用Ajax和Jquery实现GridView的展开、合并
- 使用Ajax和Jquery实现GridView的展开、合并
- Ajax应用:使用jQuery和PHP实现功能开关效果
- 使用jquery实现ajax请求示例
- jquery.form.js实现将form提交转为ajax方式提交的使用方法
- 使用JQuery快速实现Tab的AJAX动态载入(实例讲解)
- 代码下行Jquery结合Ajax和Web服务使用三层架构实现无刷新分页
- 关于jQuery使用serializeArray()序列化表单数据,使用FormData()实现AJAX请求的问题
- Jquery调用Ajax实现联动使用json
- Ajax应用:使用jQuery和PHP实现功能开关效果
- 使用jQuery轻松实现Ajax
- 使用jquery+ajax+php实现搜索框的功能
- 使用jQuery和Ajax请求实现分页效果
- 使用Jquery原理实现一个简单的Ajax的支持JS类
- 使用Ajax和Jquery配合数据库实现下拉框的二级联动
- 使用Java、Jquery、Ajax实现的带进度条的文件上传。
- Ajax02 什么是json、json语法、json的使用、利用jQuery实现ajax
- jQuery的deferred对象使用详解——实现ajax同步请求数据