Hello @everyone
I am using jQuery ajax to bind a html select list on an asp.net webform. The webmethod is executing absolutely fine but in error method as getting the above error. I searched on google and compare my code I found no differences. Please help me out of it below is my code.
$(document).ready(function () {
$.ajax({
type: "POST",
url: "ManPowerEntry.aspx/getProjectNames",
dataType: "json",
contentType: "application/json",
success: function (res) {
$("#ddlProject").empty();
$("#ddlProject").append($("<option value='0'> --Select Project--</option>"));
$.each(res.d, function (key, value) {
$("#ddlProject").append($("<option></option>").val(value.projectCode).html(value.projectName));
});
},
error: function ajaxError(result) {
alert(result.status + ' : ' + result.statusText);
}
});
});
public class ProjectManPower
{
public string projectCode{ get; set; }
public string projectName { get; set; }
}
[WebMethod]
public static List<ProjectManPower> getProjectNames()
{
string query = "select project_code, (project_code+' - '+ project_name) as ProjectName from ProjectMaster";
DataTable dt = SqlConn.SqlExce.fillDataTableRet(query);
List<ProjectManPower> lst = new List<ProjectManPower>();
foreach(DataRow dr in dt.Rows)
{
lst.Add(new ProjectManPower
{
projectCode = dr["project_code"].ToString(),
projectName = dr["ProjectName"].ToString()
});
}
return lst;
}