通过ajax调用使用web方法绑定Dropdownlist

本文关键字:方法 绑定 Dropdownlist web ajax 调用 通过 | 更新日期: 2023-09-27 17:57:38

我的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");
                }
            });
        });
    });

我的网络方法:【web方法】

  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调用的新手,我将下拉选择的值发送到我的Web方法。选择下拉列表后,我的图表不会呈现。。在选择了下拉值之后,我的图表也不会呈现。它显示错误警报。

通过ajax调用使用web方法绑定Dropdownlist

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

您需要发送一个JSON字符串。