我正在开发一种AJAX并且运行顺畅无瑕,简而言之,我没有“错误”。
有点小事情打扰我,当我去检查元素它显示这一点。当我第二次运行我的AJAX并使用不同的触发器时会发生这种情况。
我如何摆脱这条消息?同时我甚至不知道我从哪里开始这个奇怪的“syntaxerror”。
我的Ajax脚本(使用jQuery 1.10.2):
mobisuiteUserList = {
urlApiUserList:"",
urlParam:"",
currentPage:1,
limit:10,
totalPages:1,
init:function() {
self = this;
$('#viewUsersButton').click(function() {
self.currentPage = 1;
self.viewUser();
});
$(document.body).on("click","[name=pageButton]",function() {
self.currentPage = parseInt($(this).attr('data-page-id'));
self.viewUser();
});
$(document.body).on("click","#firstButtonList",function() {
self.currentPage = 1;
self.viewUser();
});
$(document.body).on("click","#prevButtonList",function() {
self.currentPage -= 1;
self.viewUser();
});
$(document.body).on("click","#nextButtonList",function() {
self.currentPage += 1;
self.viewUser();
});
$(document.body).on("click","#lastButtonList",function() {
alert(self.totalPages);
self.currentPage += self.totalPages;
self.viewUser();
});
},
viewUser:function() {
self = this;
if(typeof(self.ajax) != "undefined") {
self.ajax.abort();
}
//example
//http://192.168.7.162/user-management/index.php/user/list?data={"order":"asc","limit":2,"dateFrom":"2015-01-23","dateTo":""}
var dateFrom = $('#dateFromSelect').val();
var dateTo = $('#dateToSelect').val();
var startRecord = (self.currentPage - 1) * self.limit;
parameter = "{"+
'"order":"desc",'+
'"start":'+'"'+startRecord+'",'+
'"limit":'+'"'+self.limit+'",'+
'"dateFrom":'+'"'+dateFrom+'",'+
'"dateTo":'+'"'+dateTo+'"'+
"}";
self.ajax = $.ajax({
cache:false,
url:self.urlApiUserList + "?data="+encodeURIComponent(parameter),
beforeSend:function() {
window.scrollTo(0, 0);
$('#userListTbody').html('<tr><td colspan="6" align="center"><i>Retrieving data...</i></td></tr>');
$('#pagingUserList').html('');
$('[name=pageButton]').off();
$('#firstButtonList').off();
$('#prevButtonList').off();
$('#nextButtonList').off();
$('#lastButtonList').off();
$('#warningText').hide();
$('#userLoginLoadingAniGif').show();
},
success:function(resp) {
if(resp.trim().length > 0) {
var html = "";
var pagingHtml = "";
try {
var parsedData = $.parseJSON(resp);
var totalViewedUser = parsedData.data.length;
var totalUser = parsedData.totalRecord;
var remainingRecord = 0;
self.totalPages = Math.floor(totalUser / self.limit);
remainingRecord = totalUser % self.limit;
if(remainingRecord > 0) {
self.totalPages += 1;
}
pagingHtml = "<ul>";
self.currentPage = parseInt(self.currentPage);
if(self.currentPage == 1) {
pagingHtml += '<li class="prev disabled"><a href="#">First</a></li>';
pagingHtml += '<li class="prev disabled"><a href="#">Previous</a></li>';
} else {
pagingHtml += '<li class="prev"><a id="firstButtonList" href="#">First</a></li>';
pagingHtml += '<li class="prev"><a id="prevButtonList" href="#">Previous</a></li>';
}
//example : PREV - 17 - 18 - 19 - 20
if(self.currentPage <= 3) {
var leftBoundaryPageNumber = 1;
} else {
var leftBoundaryPageNumber = self.currentPage - 3;
}
//example : 20 - 21 - 22 - 23 - NEXT
if(self.currentPage >= self.totalPages - 3) {
var rightBoundaryPageNumber = self.totalPages;
} else {
var rightBoundaryPageNumber = self.currentPage + 3;
}
for(pageNumber=leftBoundaryPageNumber;pageNumber < self.currentPage;pageNumber++) {
if(pageNumber == self.currentPage) {
pagingHtml += '<li class="active"><a name="pageButton" href="javascript:void()" data-page-id="'+pageNumber+'">'+pageNumber+'</a></li>';
} else {
pagingHtml += '<li><a name="pageButton" href="javascript:void()" data-page-id="'+pageNumber+'">'+pageNumber+'</a></li>';
}
}
pagingHtml += '<li class="active"><a name="pageButton" href="javascript:void()" data-page-id="'+pageNumber+'">'+pageNumber+'</a></li>';
for(pageNumber=self.currentPage+1;pageNumber <= rightBoundaryPageNumber;pageNumber++) {
if(pageNumber == self.currentPage) {
pagingHtml += '<li class="active"><a name="pageButton" href="javascript:void()" data-page-id="'+pageNumber+'">'+pageNumber+'</a></li>';
} else {
pagingHtml += '<li><a name="pageButton" href="javascript:void()" data-page-id="'+pageNumber+'">'+pageNumber+'</a></li>';
}
}
if(self.currentPage == self.totalPages) {
pagingHtml += '<li class="next disabled"><a href="javascript:void()" >Next</a></li>';
pagingHtml += '<li class="next disabled"><a href="javascript:void()" >Last</a></li>';
} else {
pagingHtml += '<li class="next"><a id="nextButtonList" href="javascript:void()" >Next</a></li>';
pagingHtml += '<li class="next"><a id="lastButtonList" href="javascript:void()" >Last</a></li>';
}
pagingHtml += "</ul>";
$('#pagingUserList').html(pagingHtml);
for(index=0;index < totalViewedUser;index++) {
html += "<tr>"+
"<td>"+ parsedData.data[index].userId +"</td>"+
"<td>"+ parsedData.data[index].username +"</td>"+
"<td>"+ parsedData.data[index].firstName + " " + parsedData.data[index].lastName +"</td>"+
"<td>"+ parsedData.data[index].email +"</td>"+
"<td>"+ parsedData.data[index].createdDate +"</td>"+
"<td>"+ "<a href=''>Edit</a> | <a href=''>Delete</a>" + "</td>"+
"</tr>";
}
$('#userListTbody').html(html);
} catch(e) {
$('#warningText').show();
$(function () {
$('#warningText').tooltip({
title:"Unable to parse retrieved data"
});
});
$('#userListTbody').html('<tr><td colspan="6" align="center"><i>No data to view, please click View button to view data</i></td></tr>');
}
} else {
$('#warningText').show();
$(function () {
$('#warningText').tooltip({
title:"Unable to retrieve user data"
});
});
$('#userListTbody').html('<tr><td colspan="6" align="center"><i>No data to view, please click View button to view data</i></td></tr>');
}
$('#userLoginLoadingAniGif').hide();
},
error:function() {
$('#warningText').show();
$('#warningText').tooltip({
title:"Unable to retrieve user data"
});
$('#userLoginLoadingAniGif').hide();
$('#userListTbody').html('<tr><td colspan="6" align="center"><i>No data to view, please click View button to view data</i></td></tr>');
}
})
}
}