jquery的ajax 处理后台传来json格式的二维数组
2015-07-20 15:48
771 查看
jquery的ajax 处理后台传来json格式的二维数组
http://qqdamai.iteye.com/blog/1454383@SuppressWarnings("unchecked")
@Path("getUsers.html")
@POST
@Produces({ MediaType.APPLICATION_JSON })
public Map getUserByName(MultivaluedMap<String, String> formParams) throws Exception {
String name=formParams.getFirst("name");
String project_id=formParams.getFirst("part_id");
List Users=null;
List<Part> parts=null;
users= jpaTemplate.find("select usp.user,usp.part.id as bid from USP usp where usp.user.name like '"+"%"+name+"%'");
parts= jpaTemplate.find("select usp.part from USP usp where usp.part.id='"+part_id+"'");
Map map=new HashMap();
map.put("users", users);
map.put("parts", parts);
return map;
}
<script type="text/javascript">
function cleanVal(){
document.getElementById('name').value="";
}
function setDefault(){
var value=document.getElementById('name').value;
if(value=="" || value==null){
document.getElementById('name').value="请输入姓名";
}
}
$(document).ready(function(){
$("#search").click(function(){
$.ajax({
url:"../../app/userManage/getUsers.html",
type:"POST",
data:$("#searchCondition").serialize(),
dataType:"json",
success:function(data){
try{
var html=' ';
$.each(data.users,function(i,item){
html += '<tr><td>'+ item[0].name +'</td><td>'+ item[0].sex+'</td><td>'+ item[0].addr +'</td>';
if(item[1]==" " || item[1] == null){
html += '<td>'+"未分配"+'</td></tr>';
}else{
$.each(data.parts,function(entryIndex,entry){
if(item[1]==entry.id){
html += '<td><a href="../userManage/to-user-detail.html?part_id='+entry.id+'&user_id=${user.id}" rel="external">'+entry.name+'</a></td></tr>';
return false;
}
});
}
return true;
});
$("#puser").html(html);
}catch(e){
alert("查询员工出现异常");
return;
}
},
error:function(result,status){
if(status == 'error'){
alert(status);
}
}
});
});
});
</script>
<form id="searchCondition" rel="external" data-ajax="false" enctype1="multipart/form-data">
<input name="part_id" type="hidden" value="${part.id}" />
<table width="90%" border="0" cellpadding="0" cellspacing="0"
style="margin: 4px">
<tr style="border: 0">
<td style="border: 0">
<label>搜索员工属于哪个部门:</label>
</td>
<td style="border: 0">
<input id="name" name="name" type="search" onfocus="cleanVal()" onblur="setDefault()" value="请输入姓名" style="width: 100%" />
</td>
<td style="width: 1px; border: 0">
<input id="search" type="button" value="搜索" />
</td>
</tr>
</table>
</form>
<h3>员工属于哪个部门</h3>
<table id="title" >
<thead class="ui-bar-b">
<tr>
<th>姓名</th>
<th>性别</th>
<th>地址</th>
<th>所在部门</th>
</tr>
</thead>
<tbody id="puser">
</tbody>
</table>
相关文章推荐
- jquery.cookie中的操作
- ul li a active jquery.cookie.js
- jquery treegrid实例
- jquery选择器汇总
- 关于JQuery与AJAX验证
- JQuery事件e参数的方法preventDefault()取消默认行为
- spring mvc通过jQuery ajax传值中文乱码问题
- JQuery Mobile实例
- jQuery通过CSS()方法给指定的元素同时设置多个样式
- jquery 插件开发
- 用jquery判断输入框还可以输入多少字
- 基于jQuery的新浪游戏首页幻灯片
- JavaScript/jQuery WebIM 及时聊天通信工具 本地客户端
- 加载进度圈,带遮罩层(jquery)
- jQuery.outerWidth() 函数详解
- 关于在项目里使用jquery的ajax函数。
- jquery选中表格的某行变色
- JQuery 异步处理,ajax post get getJSON...
- jquery 自定义事件
- jquery-plugin-validate插件做验证