Javascript 解析来自ajax调用的错误
我已经使用开源库编写了一些ajax代码来执行jquery分页。 当页面首次加载时,它会正确地查询并显示数据库中的前25条记录。但所有后续请求都会失败,并出现解析错误。 我看不出第一页中的数据格式与其他页面中的数据格式有什么不同 我曾尝试使用JSON Lint,但没有一个JSON传递,甚至没有第1页的查询。 我的json数据如下所示:Javascript 解析来自ajax调用的错误,javascript,jquery,ajax,jquery-pagination,Javascript,Jquery,Ajax,Jquery Pagination,我已经使用开源库编写了一些ajax代码来执行jquery分页。 当页面首次加载时,它会正确地查询并显示数据库中的前25条记录。但所有后续请求都会失败,并出现解析错误。 我看不出第一页中的数据格式与其他页面中的数据格式有什么不同 我曾尝试使用JSON Lint,但没有一个JSON传递,甚至没有第1页的查询。 我的json数据如下所示: "[{\"createddatetime\":\"2013-09-10 17:56:54\",\"description\":\"and the final upd
"[{\"createddatetime\":\"2013-09-10 17:56:54\",\"description\":\"and the final update\",\"number\":\"72212\",\"updatedname\":\"28112\",\"createdname\":\"conversion script\",\"user\":\"28507\",\"position\":\"1\",\"device_id\":\"2\",\"user_id\":\"2\",\"password\":\"Wh16dteaR\",\"updateddatetime\":\"2013-10-07 15:14:28\"},{\"createddatetime\":\"2013-09-10 17:56:54\",\"description\":\"Bauer\",\"number\":\"72787\",\"createdname\":\"conversion script\",\"user\":\"28509\",\"position\":\"2\",\"device_id\":\"4\",\"user_id\":\"4\",\"password\":\"EHVOzIx1\"},{\"createddatetime\":\"2013-09-10 17:56:54\",\"description\":\" Woosly\",\"number\":\"72822\",\"createdname\":\"conversion script\",\"user\":\"28510\",\"position\":\"3\",\"device_id\":\"5\",\"user_id\":\"5\",\"password\":\"IP8rsdOE\"}]"
然后我使用parseJSON方法将上面的字符串转换成一个对象。
下面是进行ajax调用和解析的主要例程:
$.ajax({
url: mypath + '?startpos=' + page_index * items_per_page + '&numberofrecordstograb=' + items_per_page + '&viewtype=json',
dataType: 'json',
success: function(data){
data = $.parseJSON(data); //converting to a javascript object vs. just string...
if (data !=null) {
for(var i=0;i<data.length;i++){
var deviceobj = data[i];
newcontent = newcontent + "<TR>";
newcontent=newcontent + '<TD>';
//add EDIT hyperlink
if ($("#editdevicesettings").val() == "true") {
var temp = $("#editlinkpath").val();
newcontent=newcontent + temp.replace("xxx",deviceobj["device_id"]) + ' ';
}
//add DELETE hyperlink
if ($("#deletedevice").val() == "true") {
var temp = $("#deletelinkpath").val();
newcontent=newcontent + temp.replace("xxx",deviceobj["device_id"]);
}
newcontent=newcontent + '</TD>';
newcontent=newcontent + '<TD>' + deviceobj["number"] +'</TD>';
newcontent=newcontent + '<<TD>' + deviceobj["user"] + '</TD>';
newcontent=newcontent + '<<TD>' + deviceobj["password"] + '</TD>';
if (deviceobj["name"]) {
newcontent=newcontent + '<TD>' + deviceobj["name"] + '</TD>';
}
else {
newcontent=newcontent + '<TD> </TD>';
}
newcontent=newcontent + '<TD>' + deviceobj["description"] + '</TD>';
newcontent = newcontent + "</TR>";
}// end for
// Replace old content with new content
$('#Searchresult').html(newcontent);
}//end if
},
error: function(request, textStatus, errorThrown) {
console.log(textStatus);
},
complete: function(request, textStatus) { //for additional info
//alert(request.responseText);
console.log(textStatus);
}
});
// Prevent click eventpropagation
return false;
}//end pageselectCallback()
$.ajax({
url:mypath+'?startpos='+页面索引*每个页面的项目数+'&numberofrecordstograb='+每个页面的项目数+'&viewtype=json',
数据类型:“json”,
成功:函数(数据){
data=$.parseJSON(data);//转换为javascript对象而不是字符串。。。
如果(数据!=null){
对于(var i=0;i我决定将返回的记录数减少到每页一条……以缩小违规记录的范围。
现在我知道它是哪个记录了,我应该能够解决这个问题