jquery,ajax返回json对象,在table中显示

1.<table id="resultTable" class="sortable" width="100%" border="1" align="center" cellPadding="0" cellSpacing="0" borderColorLight="#cccccc" borderColorDark="#ffffff">  
2.    <thead>  
3.        <tr>  
4.            <td nowrap width="16%">发送号码</td>  
5.            <td nowrap width="16%">接收号码</td>  
6.            <td nowrap width="17%">日志类型</td>  
7.            <td nowrap width="17%">日志时间</td>  
8.            <td nowrap width="17%">发送状态</td>  
9.            <td nowrap width="17%">解释口径</td>  
10.        </tr>  
11.    </thead>  
12.    <tbody>  
13.        <!-- 此处显示ajax返回数据 -->  
14.    </tbody>  
15.    <tfoot>  
16.        <!-- 此处显示ajax返回数据 -->  
17.    </tfoot>  
18.</table>  
	<table id="resultTable" class="sortable" width="100%" border="1" align="center" cellPadding="0" cellSpacing="0" borderColorLight="#cccccc" borderColorDark="#ffffff">
		<thead>
			<tr>
				<td nowrap width="16%">发送号码</td>
				<td nowrap width="16%">接收号码</td>
				<td nowrap width="17%">日志类型</td>
				<td nowrap width="17%">日志时间</td>
				<td nowrap width="17%">发送状态</td>
				<td nowrap width="17%">解释口径</td>
			</tr>
		</thead>
		<tbody>
			<!-- 此处显示ajax返回数据 -->
		</tbody>
		<tfoot>
			<!-- 此处显示ajax返回数据 -->
		</tfoot>
	</table>



Javascript代码  
1.  
2.//清除Table   
3.function clearRowsSMS(){   
4.    var tableLen = document.getElementById('resultTable').rows.length;   
5.    if(tableLen > 1){   
6.        for(var i=0; i<tableLen-1; i++){   
7.            document.getElementById('resultTable').deleteRow(tableLen-i-1);   
8.        }   
9.    }   
10.}   
11.  
12.//ajax查询短信收发记录信息   
13.function searchSMS(){      
14.    if(validateSMS()){   
15.        $("#loadData").show();   
16.        $("#queryButton").attr({"disabled":"disabled"});   
17.        $.ajax({   
18.            url:'/xxxxAction.do?method=qrySMS',   
19.            data:{   
20.                faultCode: $("#linecode").val(),   
21.                startTime:$("#startTime").val(),   
22.                endTime:$("#endTime").val()   
23.            },   
24.            cache:false,//不要缓存结果数据,很重要!   
25.            dataType:'json',   
26.            error:function(){      
27.                $("#loadData").hide();   
28.                $("#queryButton").removeAttr("disabled");   
29.                clearRowsSMS();   
30.                alert("查询出错,请稍候再试!");   
31.            },      
32.            success:function(buffer){      
33.                $("#loadData").hide();   
34.                $("#queryButton").removeAttr("disabled");   
35.                clearRowsSMS();   
36.                if(buffer==undefined || buffer==""){   
37.                    $("#resultTable").find('tfoot').append("<tr><td colspan='6' align='center'>没有查到短信收发记录信息!</td></tr>");   
38.                }else{    
39.                    $.each(buffer, function(idx,item){   
40.                        $("#resultTable").find('tbody').append("<tr class='text-en-9pt'><td nowrap>"+item.inTelPhone+"&nbsp;</td><td nowrap>"+item.ountTelPhone+"&nbsp;</td><td nowrap>"+item.recordType+"&nbsp;</td><td nowrap>"+item.sendTime+"&nbsp;</td><td nowrap>"+item.msg+"&nbsp;</td><td nowrap>"+item.errhint+"&nbsp;</td></tr>");   
41.                    });   
42.                }                                           
43.            }      
44.       });    
45.    }      
46.}

转载于:https://my.oschina.net/u/175660/blog/76451

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值