-
ajax请求服务器端数据
$.ajax({
type : "POST",//请求方式
url : "${APP_PATH}/user/deletes",//请求地址
data :{ id : id },
success : function(result) {
//服务器端成功时,返回操作
});
-
HTML页面的标签拼接
jquery请求json数据,异步显示数据。采用页面标签的拼接,可以较好的实现数据的异步显示,提升页面的运行效率。在下面的代码中,tableContent 是js的全局变量,将ajax请求的json数据返回到页面后,通过each方法遍历数据,进而进行拼接。其他的HTML标签也可进行相互转换,举一反三。
$.each(users,function(i,user){
tableContent +='<tr>';
tableContent +='<td>'+(i+1)+'</td>';
tableContent +='<td><input type="checkbox"></td>';
tableContent +='<td>'+user.loginacct+'</td>';
tableContent +='<td>'+user.username+'</td>';
tableContent +='<td>'+user.email+'</td>';
tableContent +='<td>';
tableContent +='<button type="button" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-check"></i></button>';
tableContent +='<button type="button" class="btn btn-primary btn-xs"><i class=" glyphicon glyphicon-pencil"></i></button>';
tableContent +='<button type="button" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></button>';
tableContent +='</td>';
tableContent +='</tr>';
});