0

I have a small question as follow: I have a function that it takes on values input and returns JSON string. In my function GET_PRODUCT input a parameter as string @product_name . The result as JSON , I do not know how to pass parameters in here . I must declare how do use dataSrc in here (suppose webmethod GET_PRODUCT is work with parameter input )

var table;
            table = $('#div_table').DataTable({
            "processing": false,
            "serverSide": false,
            "ajax": {
                "url": "../BUS/WebService.asmx/GET_PRODUCT",
                "dataType": "json",
                "contentType": "application/json; charset=utf-8",
                "type": "POST",
                dataSrc: function (json) {
               //dataSrc: function (json(Candy)) {
                 //transfer parameter in here 
                 //result as JSON string will parsed and fill in DataTables
                    return $.parseJSON(json.d);
                },
                //dataSrc: "Candy",
            },

I do not understand the issue pass parameters in here. Please share with me. Thank guys.

2 Answers 2

1

Ok, it work follow

 "ajax": {
                "url": "../BUS/WebService.asmx/GET_PRODUCT",
                "dataType": "json",
                "contentType": "application/json; charset=utf-8",
                "type": "POST",
                data: function (data) { return "{'product_name':'Candy'}"; },
                dataSrc: function (json) { return $.parseJSON(json.d); }
            },
Sign up to request clarification or add additional context in comments.

Comments

0

You can extend the default data being send to the server by using the data parameter e.g.

  "data": function ( d ) {
    return $.extend( {}, d, {
    "product_name": "Candy"
  } );

The dataSrc parameter lets you manipulate the data that was being returned from the server. This can either be a string definining the property from the object being returned or a function which will have a single parameter, the JSON returned from the server.

  "dataSrc": function ( json ) {
    for ( var i=0, ien=json.length ; i<ien ; i++ ) {
      // manipulate the returned data in here!
    }
    return json;
  }

You can find more information on the ajax DataTable settings here.

Good luck.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.