前台通过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":"宁武"}]} 展开
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":"宁武"}]} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询