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 there’s 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 jsp file I can get the result of JsonArray:
[{"id":"57","name":"aa"},{"id":"58","name":"qq"},{"id":"59","name":"ii"},{"id":"60","name":"jenny"},{"id":"61","name":"candy"},{"id":"62","name":"f"},{"id":"63","name":"pp"},{"id":"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
}]
});
});
There's grid in output but shows no data to display. (Sorry, I can't post an image.)
Got error:
Status =parsererror, Error =SyntaxError: JSON Parse error: Unrecognized token '<'
How can I fix this problem? Thanks!