我无法解决错误,我浏览了许多网站上给出的所有建议。任何建议都会非常有帮助。提前致谢。
jQuery代码:
$(document).ready(function () {
var client = {
"clientId": $('#clientId').val(),
"firstName": $('#firstName').val(),
"lastName": null
};
var jsonReqString = JSON.stringify(client, function (key, value) {
if (typeof value == "number") return value;
if (typeof value == "boolean") return value;
return value == "" ? null : value;
});
$.ajax({
url: "/SimpleDT/search",
type: "POST",
data: jsonReqString,
dataType: "json",
jsonp: "cspcb",
contentType: "application/json",
timeout: 60000,
xhrFields: {
withCredentials: false
},
beforeSend: function (xhrObj) {},
success: function (retdata) {
alert("retdata = " + retdata);
//retdata ={"aaData": retdata};
var result_string = JSON.stringify(retdata, function (key, value) {
if (typeof value == "number") return value;
if (typeof value == "boolean") return value;
if (key == 'clientId' && value == "") return "123321";
return value == "" ? null : value;
});
var objs = jQuery.parseJSON(result_string);
console.log("result_string data=" + result_string);
console.log("Obj=" + objs);
var lang = "";
$.each(objs, function () {
lang += this['clientId'] + "--" + this['firstName'] + "--" + this['lastName'] + "--" + this['compName'] + "--" + this['fileNo'] + "--" + this['resiAddr1'] + "--" + this['resiAddr2'] + "--" + this['resiAddr3'] + "--" + this['city'] + "--" + this['pinCode'] + "--" + this['mobileNo1'] + "--" + this['mobileNo2'] + "--" + this['mobileNo3'] + "--" + this['submissionDate'] + "--" + this['reminderDate'];
console.log(lang);
lang = "";
});
$('#example').dataTable({
/* "bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Spring3Hibernate4Annotation/search",
"sServerMethod": "POST",
*/
"aaData": "result_string",
/* "aoColumns" : [ {
"mDataProp" : "clientId", sDefaultContent: "n/a"
}, {
"mDataProp" : "firstName", sDefaultContent: "n/a"
}, {
"mDataProp" : "lastName", sDefaultContent: "n/a"
}, {
"mDataProp" : "compName", sDefaultContent: "n/a"
}, {
"mDataProp" : "fileNo", sDefaultContent: "n/a"
} ] */
"aoColumns": [{
"mDataProp": "clientId"
}, {
"mDataProp": "firstName"
}, {
"mDataProp": "lastName"
}, {
"mDataProp": "compName"
}, {
"mDataProp": "fileNo"
}]
});
},
error: function (jqXHR, textStatus, errorThrown) {
alert(
"The following error occured in maintainance Query: " + textStatus, errorThrown);
}
});
});
HTML 代码:
<table cellpadding="0" cellspacing="0" border="0" class="display"
id="example">
<thead>
<tr>
<th width="20%">Client Id</th>
<th width="25%">First Name</th>
<th width="25%">Last Name</th>
<th width="15%">Comp Name</th>
<th width="15%">File No</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>Client Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Comp Name</th>
<th>File No.</th>
</tr>
</tfoot>
</table>
示例:我从 spring 控制器收到的 JSON 响应:
[{
"clientId": "12345",
"firstName": "fgh",
"lastName": "",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "1234",
"firstName": "",
"lastName": "",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "1234765",
"firstName": "XXXXX",
"lastName": "sdgg",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "2222222",
"firstName": "dghdhfjfj",
"lastName": "gsjdjkvbcb",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "2222222123",
"firstName": "dghdhfjfj",
"lastName": "gsjdjkvbcb",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "2312234412",
"firstName": "fdsffsf",
"lastName": "fsfggg",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "2313377",
"firstName": "fdsffsf",
"lastName": "fsfggg",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "23133772",
"firstName": "ASDFREW",
"lastName": "Bandalu",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "23133773",
"firstName": "SASASAS",
"lastName": "BDDFFDDDD",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "23133774",
"firstName": "SDASADDS",
"lastName": "DFASDFF",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "23133775",
"firstName": "SDASDADD",
"lastName": "DSADFFFDD",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "23133776",
"firstName": "ASSSSS",
"lastName": "DDDSSSS",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "23133777",
"firstName": "LKJKLLKK",
"lastName": "LPSLDFF",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "23133778",
"firstName": "ASDFREW",
"lastName": "Bandalu",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "2313389",
"firstName": "fdsffsf",
"lastName": "fsfggg",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "2344",
"firstName": "fdsffsf",
"lastName": "fsfggg",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "234412",
"firstName": "fdsffsf",
"lastName": "fsfggg",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "23441q2",
"firstName": "fdsffsf",
"lastName": "fsfggg",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "23456",
"firstName": "Rajiv",
"lastName": "Muddas",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "33333333",
"firstName": "Jhon",
"lastName": "Muddas",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "3333333333",
"firstName": "RA",
"lastName": "Gulit",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "43568",
"firstName": "AFSF",
"lastName": "ADFFGGSDF",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "444444444",
"firstName": "Raju",
"lastName": "cgdhh",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}, {
"clientId": "55555",
"firstName": "Jhon",
"lastName": "Muddas",
"compName": null,
"fileNo": null,
"resiAddr1": null,
"resiAddr2": null,
"resiAddr3": null,
"city": null,
"pinCode": null,
"mobileNo1": null,
"mobileNo2": null,
"mobileNo3": null,
"submissionDate": null,
"reminderDate": null
}]