Send AJAX in to kendo ui Datagrid

2 posts, 0 answers
  1. Supaluk Jarungpornswat
    Supaluk Jarungpornswat avatar
    7 posts
    Member since:
    Jul 2018

    Posted 11 Jul 2018 Link to this post

    If I send like this  data: {CusCode:'5555', MktID: "aa"}

    0=%7B&1=C&2=u&3=s&4=C&5=o&6=d&7=e&8=%3A&9=%20&10='&11='&12=%2C&13=M&14=k&15=t&16=I&17=D&18=%3A&19=%20&20='&21=a&22=a&23='&24=%7D

    When I Use AJAX 

    HOW TO USE like this   data: "{Field:'',Text:'',page:1,rows:50000}" and don't enclipe my code

    $.ajax({ type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "Service.asmx/M_Portfolio_selMaster",
                dataType: "json",
                data: "{Field:'',Text:'',page:1,rows:50000}",
                async: true,
                success: function (response) {
                    var data = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                    var tbl;
                    data = data.rows;
                    if (data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            tbl += "<OPTION value='" + data[i]['PortfolioID'] + "'>" + data[i]['PortfolioCode'] + "</OPTION>";
                        }
                        $("#s").html(tbl);
                    }
                }
            });

     

     $("#grid").kendoGrid({
                    dataSource: {
                        transport: {
                            read: {
                                // the remote service url
                                url: "wsCRM.asmx/crm_FinancialBenefitByCustomer", // GetBBGToADVTransactionsData is our web method

                                contentType: "application/json; charset=utf-8",

                                type: "POST",

                                // JSONP is required for cross-domain AJAX
                                dataType: "json",

                                // additional parameters sent to the remote service
                                data: {
                                    CusCode:'5555',
                                    MktID: "aa"
                                }

                            }
                        }

                }

    });

    My Web service asp.net C#

        [WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string crm_FinancialBenefitByCustomer(string CusCode,string MktID)
        {
            CRMDataContext dtx = new CRMDataContext();
            var data = dtx.crm_FinancialBenefitByCustomer(CusCode, MktID, UserID).ToList();

            JavaScriptSerializer js = new JavaScriptSerializer();
            string strJSON = js.Serialize(data);
            //strJSON = "{\"__count\":\"" + data.Count + "\" ,\"results\":" + strJSON + "}";
            return strJSON;
        }

     

  2. Tsvetina
    Admin
    Tsvetina avatar
    2481 posts

    Posted 13 Jul 2018 Link to this post

    Hi Supaluk,

    The problem is most probably related to the quotes around the data object value. This needs to be a JavaScript object, as compared to a string:
    $.ajax({ type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "Service.asmx/M_Portfolio_selMaster",
                dataType: "json",
                data: "{Field:'',Text:'',page:1,rows:50000}",
                async: true,
                success: function (response) {
                    var data = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                    var tbl;
                    data = data.rows;
                    if (data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            tbl += "<OPTION value='" + data[i]['PortfolioID'] + "'>" + data[i]['PortfolioCode'] + "</OPTION>";
                        }
                        $("#s").html(tbl);
                    }
                }
            });

    Try removing the quotes and see if the issue is resolved.

    Regards,
    Tsvetina
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top