通过Ajax调用使用Web方法绑定Dropdownlist [英] Bind Dropdownlist using web method by ajax call

查看:60
本文介绍了通过Ajax调用使用Web方法绑定Dropdownlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Ajax呼叫:

 jQuery(document).ready(function () {
        $("#ddl").change(function () {
            var id = $(this).find(":selected").val()
          $.ajax({
             type: "POST",
             url : "HazzardsDashBoards.aspx/GetReport1",
            data: "JSON.stringify(id)",                
            contentType: 'application/json',
            dataType: 'json',
                complete: function (data) {

                    var data = JSON.stringify(data);

                },
                error :function()
                {
                  alert("error");
                }
            });
        });
    });

我的网络方法: [网络方法]

My webmethod: [web method]

  public static List<Dictionary<string, object>> GetReport1(string id)
            {
                List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();             

                    string strQry = string.Empty;

                    strQry = " select YEAR(mwl.dt_ModifiedOn)[date],COUNT(*) [HazardCount] from tbl ";
                    strQry += " left outer join TRANS_HAZARD_HAZARD_DETAILS thzd on thzd.int_HAZARD_ID = mwl.str_ObjectID";
                    strQry += " where int_PluginID = 4 and int_FeatureID=35 ";
                    if (id != "")
                    {
                        if (id == "1")
                        {
                            strQry += " and  col= 'E'";
                        }
                        else
                        {
                            strQry += " and  col= 'C'";
                        }
                    }                     

                    strQry += " group by year(mwl.dt_ModifiedOn) ";

                    using (commonManager)
                    {
                        DataTable dt = commonManager.ExecuteDataTable(strQry);

                        Dictionary<string, object> row;
                        foreach (DataRow dr in dt.Rows)
                        {
                            row = new Dictionary<string, object>();
                            foreach (DataColumn col in dt.Columns)
                            {
                                row.Add(col.ColumnName, dr[col]);
                            }
                            rows.Add(row);
                        }
                    }                   
                return rows;
            }

我是Ajax Call的新手,我将下拉选择的值发送到我的webmethod.选择下拉列表后,我的图表未呈现..选择下拉列表值后,我的图表也未呈现. 它显示错误警报.

I am new to Ajax Call i send dropdown selected values to my webmethod. after selection of dropdown my charts are not rendering.. And after selection of dropdown values also my charts are not rendering . It is showing error alert.

推荐答案

将此-> data: "JSON.stringify(id)"更改为data : JSON.stringify({"clientID":id}).

您需要发送JSON字符串.

You need to send a JSON string.

这篇关于通过Ajax调用使用Web方法绑定Dropdownlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆