0

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
2
  • 1
    I would prefer data: JSON.stringify({query:query,tbl:tbl,para:para,spname:spname,cmdtype:cmdtype}) rather than string concatenation. Problem with your version is that you missed quotes before in snippet { query Commented May 7, 2014 at 11:24
  • 1
    thanks.give it as solution. i will mark it as solution Commented May 7, 2014 at 11:43

1 Answer 1

1

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})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.