基于ajax后台返回的数据为空前台显示出现undefined的解决方法
之前自己做的一个图书管理系统,显示图书借阅排行榜,因为翻译在数据库中有为空的字段,故前台显示会显示undefined。
以下贴上部门代码:
$(document).ready(function () { $("#rankTable tbody").html(""); var id = 1; $.ajax({ url:"bookInfo/bookInfo_rank.action", type:"POST", data:{}, dataType:"json", success:function (data) { $(data).each(function(i,item) { var index = id++; var bookId = item.bookId; var bookName = item.bookName; var author = item.author; //判断是否为空出现undefined; var translator = (item.translator==undefined ?"":item.translator); var ISBN = item.ISBN; var press = item.press; var page = item.page; var bookCase = item.bookCase; var totalNum = item.totalNum; var stock = item.stock; var borrowNum = item.borrowNum; var typeName = item.typeName; var str = '<tr> ' + '<td>' + index + '</td>' + '<td>' + bookId + '</td>' + '<td>' +bookName + '</td>' + '<td>' + author+ '</td>' +'<td>'+translator+ '</td>' +'<td>'+ISBN+ '</td>' +'<td>'+press+ '</td>' +'<td>'+page+ '</td>' +'<td>'+bookCase+ '</td>' +'<td>'+totalNum+ '</td>' +'<td>'+stock+ '</td>' +'<td>'+borrowNum+ '</td>' +'<td>'+typeName+ '</td></tr>'; $("#rankTable tbody").append(str); str = ""; }) }, error:function(XMLHttpRequest, textStatus, errorThrown){ alert("系统异常,请稍后重试!"); alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); } }) });
相关推荐
zrtlin 2020-11-09
xuebingnan 2020-11-05
wikiwater 2020-10-27
heheeheh 2020-10-19
Crazyshark 2020-09-15
softwear 2020-08-21
ZGCdemo 2020-08-16
jczwilliam 2020-08-16
littleFatty 2020-08-16
idning 2020-08-03
jinxiutong 2020-07-26
lanzhusiyu 2020-07-19
Skyline 2020-07-04
xiaofanguan 2020-06-25
Aveiox 2020-06-23
dragonzht 2020-06-17