This is a migrated thread and some comments may be shown as answers.

Problem sending json data to ASMX webservice

2 Answers 463 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Doug Riley
Top achievements
Rank 1
Doug Riley asked on 06 Feb 2012, 06:29 PM
I am using the autocomplete component to interact with an ASMX webservice ... when I "hard code" the value to send as a parameter, it works fine:

      data: {
             sProductDesc: "E" 
      } // data

Data Posted: 
{"sProductDesc":"E","take":10,"skip":0,"page":1,"pageSize":10,"filter":{"logic":"and","filters":[{"field":"GROUP_NAME","operator":"contains","value":"e"}]},"group":[]}
      
but when I try and use the value from the control the parameter is not passed to the webservice:

      data: {
            sProductDesc: function(){return $("#autoComplete").data("kendoAutoComplete").value()} 
      } // data
Data Posted:
{"take":10,"skip":0,"page":1,"pageSize":10,"filter":{"logic":"and","filters":[{"field":"GROUP_NAME","operator":"contains","value":"E"}]},"group":[]}

Any ideas?  
Thanks!
Doug




2 Answers, 1 is accepted

Sort by
0
Doug Riley
Top achievements
Rank 1
answered on 06 Feb 2012, 10:09 PM
Just in case this may help someone else, here is the correct code:

THIS WORKS
data: function () {
             return { sProductDesc: $("#autoComplete").data("kendoAutoComplete").value() }
         } // data

THIS DOES NOT WORK
data: {
            sProductDesc: function(){return $("#autoComplete").data("kendoAutoComplete").value()} 
      } // data 

I saw the code that does not work in several samples - not sure why the sample way does not work.

Doug 
0
Doug Riley
Top achievements
Rank 1
answered on 06 Feb 2012, 10:53 PM
Complete Example of using AutoComplete with ASMX Webservice:

WEBPAGE CODE 

   <div id="autoCompleteX" class="k-content">
        <input id="autoComplete" />
        <script>
            $(document).ready(function () {


                $("#autoComplete").kendoAutoComplete({
                    change: function (e) {
                        onChange(e);
                    },
                    minLength: 1,
                    dataTextField: "GROUP_NAME",
                    filter: "contains",
                    dataSource: new kendo.data.DataSource({
                        type: "json",
                        transport: {
                            read: {
                                type: "POST",
                                url: "wsPDM.asmx/GetSeriesInfo",
                                contentType: 'application/json; charset=utf-8',
                                datatype: "json",
                                data: function () {
                                    return {
                                        sProductDesc: $("#autoComplete").data("kendoAutoComplete").value()
                                    }
                                } // data
                            }, //read
                            parameterMap: function (options) {
                                return JSON.stringify(options);
                            } // parameterMap
                        }, // transport
                        serverFiltering: true,
                        serverSorting: true,
                        pageSize: 10,
                        schema: {
                            data: "d"
                        } // schema
                    })
                }) //datasource


            });

   </script>
</div>

WEB SERVICE CODE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class wsPDM : System.Web.Services.WebService
{


    public class ProductList
    {
        public string GROUP_NAME;
        public string GROUP_ID;
        public string SERIES_NAME;
        public string SERIES_ID;
    }


    public wsPDM()
    {

    }


    [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
    [WebMethod]
    public List<ProductList> GetSeriesInfo(string sProductDesc)
    {

        List<ProductList> listProduct = new List<ProductList> { };
        listProduct.Add(new ProductList { GROUP_NAME = "E123", GROUP_ID = "124", SERIES_NAME = "E12", SERIES_ID = "E12" });
        listProduct.Add(new ProductList { GROUP_NAME = "E124", GROUP_ID = "135", SERIES_NAME = "E12", SERIES_ID = "E12" });
        listProduct.Add(new ProductList { GROUP_NAME = "E125", GROUP_ID = "136", SERIES_NAME = "E12", SERIES_ID = "E12" });
        listProduct.Add(new ProductList { GROUP_NAME = "E126", GROUP_ID = "137", SERIES_NAME = "E12", SERIES_ID = "E12" });
        return listProduct;

    }


}



Tags
AutoComplete
Asked by
Doug Riley
Top achievements
Rank 1
Answers by
Doug Riley
Top achievements
Rank 1
Share this question
or