ajax webmethod is not working while dropdown bind
What I have tried:
<select class="filter_select" id="sr_picker" ">
</select>
<script type="text/javascript">
google.setOnLoadCallback(loadsr);
function loadsr() {
// alert();
$.ajax({
url: "/webmethod.aspx/Getsr",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(r) {
var ddlsection = $("[id*=sr_picker]");
//alert(ddlsection);
ddlsection.empty().append('<option selected="selected" value="0">All</option>');
$.each(r.d, function() {
ddlsection.append($("<option></option>").val(this['Value']).html(this['Text']));
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('Got an Error ');
}
});
}
</script>
public static List<listitem> Getsr()
{
MasterLogic objMas = new MasterLogic();
// Utilities objUtl = new Utilities();
List<listitem> sectionname = new List<listitem>();
string qry = "select sales_person_code,sales_person_name from sales_personnel";
DataTable dt = objMas.GetDataTable(qry);
if (dt == null)
return sectionname;
List<datarow> list = dt.AsEnumerable().ToList();
for (int j = 0; j < dt.Rows.Count; j++)
{
sectionname.Add(new ListItem
{
Value = list[j].ItemArray[0].ToString(),
Text = list[j].ItemArray[1].ToString()
});
}
return sectionname;
}