我正在尝试从ame调用webmethod传递一些数据参数。但它没有将它们传递给web方法。以下是代码
function databind(query,tbl,para,spname,cmdtype){
$.ajax({
type: "POST",
url: "editviewposition.aspx/threeDTable",
data: "{query':'"+query+"','tbl':'"+tbl+"','para':'"+para+"','spname':'"+spname+"','cmdtype':'"+cmdtype+"'}", // here is the problem
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response);
},
error: function (response) {
alert(response);
}
});
}
的webmethod
<WebMethod()> _
<ScriptMethod()> _
Public Shared Function threeDTable(ByVal query As String, ByVal tbl As String, ByVal para() As Object, ByVal spname As String, ByVal cmdtype As String) As Object()()()
'code
End Function
答案 0 :(得分:1)
您的版本问题是您在代码段data: "{query':'
但我建议您使用JSON.stringify()
JSON.stringify()方法将值转换为JSON,如果指定了replacer函数,则可以选择替换值,或者如果指定了replacer数组,则可选地仅包括指定的属性。
代码示例
data: JSON.stringify({query:query,tbl:tbl,para:para,spname:spname,cmdtype:cmdtype})