日期:2014-05-16  浏览次数:20376 次

jquery,ajax返回json对象,在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>



//清除Table
function clearRowsSMS(){
	var tableLen = document.getElementById('resultTable').rows.length;
	if(tableLen > 1){
		for(var i=0; i<tableLen-1; i++){
			document.getElementById('resultTable').deleteRow(tableLen-i-1);
		}
	}
}

//ajax查询短信收发记录信息
function searchSMS(){ 	
	if(validateSMS()){
		$("#loadData").show();
		$("#queryButton").attr({"disabled":"disabled"});
		$.ajax({
			url:'/xxxxAction.do?method=qrySMS',
			data:{
             	faultCode: $("#linecode").val(),
             	startTime:$("#startTime").val(),
             	endTime:$("#endTime").val()
            },
            cache:false,//不要缓存结果数据,很重要!
            dataType:'json',
            error:function(){   
                $("#loadData").hide();
                $("#queryButton").removeAttr("disabled");
                clearRowsSMS();
                alert("查询出错,请稍候再试!");
			},   
			success:function(buffer){ 	
				$("#loadData").hide();
				$("#queryButton").removeAttr("disabled");
				clearRowsSMS();
				if(buffer==undefined || buffer==""){
					$("#resultTable").find('tfoot').append("<tr><td colspan='6' align='center'>没有查到短信收发记录信息!</td></tr>");
				}else{ 
					$.each(buffer, function(idx,item){
						$("#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>");
					});
				}                                        
			}   
       }); 
    }   
}