JQWidgets - Jqxgrid "no data to display", JSON Parse error
I follow the steps of this example ( http://www.jqwidgets.com/jquery-widgets-documentation/documentation/java-integration/bind-jquery-grid-to-mysql-database-using-jsp.htm ) but no data to display.
Jqxgrid.jsp file:
ResultSet result = state.executeQuery(sql1);
JsonArray recordsArray = new JsonArray();
while (result.next()) {
JsonObject currentRecord = new JsonObject();
currentRecord.add("id",
new JsonPrimitive(result.getString("id")));
currentRecord.add("name",
new JsonPrimitive(result.getString("name")));
recordsArray.add(currentRecord);
}
out.print(recordsArray);
out.flush();
In the jsp file, I can get the JsonArray result:
[{"ID": "57", "name": "aa"}, {"ID": "58", "name": "QQ"}, {"ID": "59", "name": "II"}, {"ID": "," name 60 "": "Jenny"}, {"ID": "61", "name": "candy"}, {"ID": "62", "name": "e"}, {"identifier": "63", "name": "pp"}, {"identifier": "66", "name": "KKK"}]
jqxgrid.html file:
$(document).ready(function () {
var source = {
datatype: "json",
datafields: [{name: 'id'},
{name: 'name'}],
url:"jqxgrid.jsp"
};
var dataAdapter = new $.jqx.dataAdapter(source, {
downloadComplete: function (data, status, xhr) { },
loadComplete: function (data) { },
loadError: function (xhr, status, error) {alert('Status ='+ status +', Error ='+ error ); }
});
$("#jqxgrid").jqxGrid({
width: 400,
autoheight: true,
source: dataAdapter,
columns: [{
text: 'ID',
datafield: 'id',
width: 200
}, {
text: 'Name',
datafield: 'name',
width: 200
}]
});
});
The grid is displayed here, but there is no data to display. (Sorry, I cannot post the image.)
Received error:
Status = parsererror, Error = SyntaxError: JSON parsing error: unrecognized token '<'
How can I fix this problem? Thank!
source to share
I think your problem is that you are not entering a description of the original data (client side). 4th record id is 60, which is character. The documentation states that type is a required field (although their examples don't always use it.)
If you add the type datafields:[{name:'id',type:'int'},
to var source = {
, it might solve your problem. You can also use 'number'
as type for id. He can also pay to add a type 'string'
to the field name
.
Hope this works for you.
source to share