Ajax查询
后端controller层
@ResponseBody
@RequestMapping("/getPages")
public List<Pages> getPages() {
List<Pages> findAll = pagesService.findAll();
return findAll;
}
前端ajax
$.ajax({
type: 'post',
url: 'findAll',
success: function(data) {
if (data != '') {
for(var i = 0; i < data.length; i++) {
var id = data[i].empId;
//创建一个dom元素
var inp = $("<input />");
//设置css样式为隐藏
inp.css("display", "none");
//添加value值
inp.val(data[i].request);
//添加class属性
inp.attr("class", id);
//在给定id后面追加元素
$("#"+id).append(inp);
}
}else{
console.log("数据为空");
}
},
error: function(e) {
alert(e.status);
location.reload();
}
});
本人初学,所有信息来自网络;如有遗漏感谢指正。此文仅为记录