前台通过ajax得到的json数据,怎么放入到easyui的datatrid中

<scripttype="text/javascript">window.onload=function(){$('#dg').datagrid({columns:[[{... <script type="text/javascript">
window.onload = function(){
$('#dg').datagrid({
columns:[[
{field:'id',title:'车次',width:100},
{field:'startlocation',title:'始发站',width:100},
{field:'price',title:'Price',width:100,align:'right'} ]]
});
};

function search(){
//不分页了
var startlocation = document.getElementById("startlocation").value;
var endlocation = $("#endlocation").val();
var starttime = $("#starttime").val();
alert(endlocation);
$.ajax({
type: "POST",
url: "<%=request.getContextPath()%>/ticket",
data: "op=search&startlocation=" + startlocation + "&endlocation=" + endlocation +"&starttime=" + starttime,
success: function(msg){
alert( "Data Saved: " + msg );
$('#dg').datagrid('loadData',msg); //这里为什么没效果
}
});
}
</script>
</head>

<body>
<table>
<tr>
<td>始发站:</td><td><input type="text" id="startlocation" name="startlocation" class="easyui-textbox"/></td>
<td>终点站:</td><td><input type="text" id="endlocation" name="endlocation" class="easyui-textbox"/></td>
<td>开车时间:</td><td><input id="starttime" class="easyui-timespinner" style="width:90px;" name="starttime" data-options="min:'08:30',showSeconds:false"/></td>
<td><input type="button" value="搜索" onclick="search()"/></td>
</tr>
</table>
<div style="margin:20px 0;"></div>

<table id="dg" ></table>
</body>
</html>

上面alert的结果:
Data Saved: {"total":20,"rows":[{"endtime":"1970-01-01 12:30:00.0","id":"xx112","starttime":"1970-01-01 08:30:00.0","endlocation":"太原","surplus":14,"startlocation":"晋中"},{"endtime":"1970-01-01 11:30:00.0","id":"xx123","starttime":"1970-01-01 08:30:00.0","endlocation":"太原","surplus":12,"startlocation":"宁武"}]}
展开
 我来答
weixiao800
2015-04-10 · TA获得超过824个赞
知道小有建树答主
回答量:482
采纳率:0%
帮助的人:431万
展开全部
你的msg现在是字符串格式的吧?把它转成json对象
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
浪里寻花0Z
2018-01-09
知道答主
回答量:2
采纳率:0%
帮助的人:1684
展开全部

我和你一样的遇到这个问题,后来我在easyui手册上找到这个,就ok了

源码如下:

希望对你有用

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式