我按照这个例子的步骤(http://www.jqwidgets.com/jquery-widgets-documentation/documentation/java-integration/bind-jquery-grid-to-mysql-database-using-jsp.htm),但是没有可显示的数据。
jqxgrid.jsp 文件:
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();
在 jsp 文件中我可以得到 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 文件:
$(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
}]
});
});
输出中有网格,但没有显示数据。(抱歉,我无法发布图片。)
得到错误:
状态 =parsererror,错误 =SyntaxError:JSON 解析错误:无法识别的令牌 '<'
我该如何解决这个问题?谢谢!