先说结论:
返回值需要放在response对象中,格式为html样式;其他无论是String、JSON、Array均会报一个解析错误
示例:
/**
* java示例代码
*/
@RequestMapping("/phone/type")
public void channel(ServletResponse response) throws IOException {
System.err.println("查询手机类型");
response.setCharacterEncoding("UTF-8");
response.getWriter().write("<select>" +
"<option value=1>小米</option>" +
"<option value=2>华为</option>" +
"<option value=3>苹果</option>" +
"</select>");
}
// js示例代码
$("#jqGrid").jqGrid({
url: '/phone/list',
datatype: "json",
colModel: [{
label: '手机类型',
name: 'type',
editable: true,
edittype: 'select',
editoptions: {dataUrl:'/phone/type'}
}],
viewrecords: true,
height: 500,
rowNum: 10,
rowList : [10,30,50],
rownumbers: true,
rownumWidth: 30,
autowidth:true,
pager: "#jqPager"
});