从$传递多个数据参数.Ajax到webmethod



我试图从ajax调用webmethod传递一些数据参数。但它不会把它们传递给webmethod。下面是代码

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

您的版本的问题是您在代码片段data: "{query':' 查询之前缺少引号

但是我建议你使用JSON.stringify()

JSON.stringify()方法将值转换为JSON,如果指定了替换函数,则可选地替换值,如果指定了替换数组,则可选地只包含指定的属性。

代码示例

data: JSON.stringify({query:query,tbl:tbl,para:para,spname:spname,cmdtype:cmdtype})

最新更新