c# - Json Dropdown Postback Response -
my ajax calls:
$(document).ready(function() { $.ajax({ type: "post", url : "hazzardsdashboards.aspx/getreport", data: "{}", contenttype: 'application/json', datatype: 'json', complete: function (jqxhr) { var data = json.parse(jqxhr.responsetext); trendchart(data); }, error: function (error) { alert("error"); } }); $(".ddlchange").change(function () { $.ajax({ type: "post", url : "hazzardsdashboards.aspx/getreport1", data: json.stringify({ company: $("#ddl_permitcmpny").val(), dept: $("#ddl_agency").val() }), contenttype: 'application/json', datatype: 'json', complete: function (jqxhr) { var data = json.parse(jqxhr.responsetext); trendchart(data); }, error :function(jqxhr,textstatus,errorthrown) { alert("an error occurred whilst trying contact server: " + jqxhr + " " + textstatus + " " + errorthrown); } }); }); });
server methods:
[webmethod] public static list<dictionary<string, object>> getreport() { list<dictionary<string, object>> rows = new list<dictionary<string, object>>(); try { string strqry = string.empty; strqry = " select year(dt_modifiedon)[date],count(*) [hazardcount] tbl"; strqry += " int_pluginid = 4 , int_featureid=35 "; strqry += " group year(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); } } } catch (exception ex) { throw ex; } return rows; } [webmethod] public static list<dictionary<string, object>> getreport1(string company, string dept) { list<dictionary<string, object>> rows = new list<dictionary<string, object>>(); try { string strqry = string.empty; strqry = " select year(mwl.dt_modifiedon)[date],count(*) [hazardcount] tbl"; strqry += " left outer join tbl1 thzd on thzd.int_hazard_id = mwl.str_objectid"; strqry += " int_pluginid = 4 , int_featureid=35 "; if (company != "") { if (company == "1") { strqry += " , str_reportfromtype = 'e'"; } else { strqry += " , str_reportfromtype = 'c'"; } } if (dept != null && dept != string.empty) { if (company == "1") { strqry += " , thzd.str_72_me = '" + dept + "' "; } if (company == "2") { strqry += " , thzd.smallint_5865_me = '" + dept + "' "; } } strqry += " group 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); } } } catch (exception ex) { throw ex; } return rows; }
i getting same json response both ajax calls, after dropdown selection getting same json response. data overriden after dropdown selection , data not being reflected.
ajax call firing , going respective method data not being reflected , showing same data. need different json responses different ajax calls when dropdown changes , page load.
please note first ajax call run every single time page loads.i'm suspecting after call getreport1()
post happens , jquery load event runs override trendchart()
logic calling getreport()
.
you can place alert('page loading...');
statement after $(document).ready(function(){
test theory.
you using asp.net dropdownlist
control causes post back, if that's case try replacing simple html <select>
, see if fixes problem
Comments
Post a Comment