第一种写法:
//准备参数
var ldc="lxr="+lxr+"&djrq="+djrq+"&djrq2="+djrq2+"&czrq="+czrq+"&czrq2="+czrq2;
$.ajax({type:'GET',
data:ldc,
url:"__APP__/Jtbc/findldc",
success:function(data){
data = data.info;
//alert(data);
if (data){
$("#tb2").find('tr').remove();
var str='';
$.each(data,function (j,item){
str+='<tr onclick="selectrow(this,'+item['xh']+','+item['djid']+')"><td style="width:5%;text-align:center;">'+item['xh']+'</td><td style="width:10%;text-align:center;">'+item['djid']+'</td><td style="width:15%;text-align:center;">'+item['djrq']+'</td><td style="width:15%;text-align:center;">'+item['djr']+'</td><td style="width:10%;text-align:center;">'+item['lxr']+'</td><td style="width:10%;text-align:center;">'+item['lxdh']+'</td><td style="width:10%;text-align:center;">'+item['xm']+'</td><td style="width:10%;text-align:center;">'+item['xb']+'</td><td style="width:10%;text-align:center;">'+item['nl']+'</td></tr>';
});
$("#tb2").append(str);
$("#tb2 tr:odd").css('background-color','#D6DDFA');
$("#tb2 tr:even").css('background-color','#ffffff');
}else{
alert('没有查询到此病人');
}
}
});
第二种写法:
//准备参数 var param = {"operation": $("#operation").val(),"dept_name": $dept_name,"section_id": $("#section_id").val()}; //调用ajax方法执行新增或修改操作 $.post("URL",param,function (data) { if($("#operation").val() == '1') { //新增返回的结果为新增部门的id var $dept_id = data; //把新增的部门表示为当前选中部门的子节点 //判断当前选中部门是否已经存在子节点 var $next = $(".selected").next(); var show_list; //如果不存在子节点 if($next.length == 0) { //首先增加ul元素 show_list = $('<ul class="branch in"></ul>'); $(".selected").parent().append(show_list); $(".selected").addClass('tree-toggle'); } else { show_list = $next[0]; } var a = $('<a href="#" data-role="branch" class="tree-node"></a>'); var li = $('<li></li>'); a.html($dept_name); a.attr('tag',$dept_id); li.append(a); show_list.append(li); } else{ var $save = data; if ($save == 1){ $(".selected").html($dept_name); } } });原文链接:https://www.f2er.com/ajax/163647.html