我试图将参数从jsTree 3.0.2传递到aspx页面上的Web方法,但它没有达到Web方法。但是,当没有参数时,它确实有效。任何人都可以指出我的方式错误吗?
使用参数(不工作):
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static IEnumerable<JsTreeNode> GetAll(string id)
{
// method does not get called
}
$("#jsTreeTest").jstree({
"core": {
"data": {
"url": "MyPage.aspx/GetAll",
"type": 'POST',
"dataType": 'JSON',
"contentType": 'application/json;',
'data': function (node) {
return { 'id': "01" };
}
}
}
});
没有参数(工作):
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static IEnumerable<JsTreeNode> GetAll()
{
// successfully calls method
}
$("#jsTreeTest").jstree({
"core": {
"data": {
"url": "MyPage.aspx/GetAll",
"type": 'POST',
"dataType": 'JSON',
"contentType": 'application/json;',
"data": function (node) { return {}; }
}
}
});
谢谢。
答案 0 :(得分:3)
发现问题。它应该是:
return '{ "id" : "01" }';
工作代码:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static IEnumerable<JsTreeNode> GetAll(string id)
{
// success!
}
$("#jsTreeTest").jstree({
"core": {
"data": {
"url": "MyPage.aspx/GetAll",
"type": 'POST',
"dataType": 'JSON',
"contentType": 'application/json;',
"data": function (node) {
return '{ "id" : "01" }';
}
}
}
});