King of kings
King of kings

Reputation: 695

Passing multiple data parameters from $.ajax to webmethod

I am trying to pass some data parameters from ajax call for webmethod. but it doesn't pass them to the webmethod. following is the code

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

Upvotes: 0

Views: 503

Answers (1)

Satpal
Satpal

Reputation: 133453

Problem with your version is that you missed quotes before query in snippet data: "{query':'

However I would recommend you to use JSON.stringify()

The JSON.stringify() method converts a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.

Code Example

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

Upvotes: 1

Related Questions