jqGrid一直在踢我的屁股(以及本网站上的其他人)。我似乎无法从web服务获取JSON数据以在使用addJSONData方法时加载到jqGrid中。你可以在ASP.net中使用web服务和JavaScript使用jqGrid吗?
有谁知道这是可能做到的吗?我没有在ASP.NET 3.5中使用MVC只是一个简单的WebProject web服务。
我使用的是最新版本的jqGrid 3.5。
我不知道该怎么做。目前我正在试图加载仅1行,我在我的WS这样返回一个字符串:
"Page:1,Total:1,Records:1,Rows:[name: Jeff V title: Programmer]"
然后传递到我的javascript为: {“d”:“页:1,总计: 1,记录:1,行:名称:杰夫·瓦卡罗标题:程序员]“}
我的jQuery代码如下:
jQuery(document).ready(function() {
jQuery("#list").jqGrid({
datatype: processrequest,
mtype: 'POST',
colNames: ['Name', 'Title'],
colModel: [
{ name: 'name', index: 'name', width: 55 },
{ name: 'title', index: 'title', width: 90 }
],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'id',
sortorder: "desc",
viewrecords: true,
imgpath: 'themes/basic/images',
caption: 'My first grid'
});
});
function processrequest(postdata) {
$(".loading").show();
$.ajax({
type: "POST",
data: "{}",
datatype: "clientside",
url: "../webServices/myTestWS.asmx/testMethod",
contentType: "application/json; charset-utf-8",
complete: function (jsondata, stat) {
if (stat == "success") {
jQuery("#list")[0].addJSONData(eval("(" + jsondata.responseText + ")"));
$(".loading").hide();
} else {
$(".loading").hide();
alert("Error with AJAX callback");
}
}
});
}
我已经试过了各种的addJSONData代码的不同变化。有谁知道这是可能做到的吗?
任何帮助表示赞赏!
感谢
OK ......在更改我的WS后,回拉一个非常简单的测试对象,它返回总数,页面,记录和行(列表数据类型),然后在WS中使用以下内容: _ _ 我还添加: jsonReader:{ 根: “行”, 页: “页”, 总: “总”, 记载: “记录”, repeatitems :false, id:“ID”//带有PK的列的索引 }, 给我的J avaScript文件。 毕竟它终于奏效了。 –
webdad3
2010-06-30 20:54:56