I am calling function from .asmx.cs file by ajax web method. Now, I am getting output undefined value in ajax success.
Here is my code,
<input type="button" id="btnGetStock" value="View" class="button-89" />
$("#btnGetStock").click(function (e) {
var dataToSend = {
labelno: document.getElementById("<%=txt_labelno.ClientID%>").value
};
$.ajax({
type: "POST",
url: "FillGridMethod.asmx/QuotationList",
data: dataToSend,
dataType: "json",
success: function (data) {
alert(JSON.stringify(data.ItemType));
$("#lbl_type").val(data.ItemType);
}
});
});
Here is the .asmx file
[WebMethod(enableSession: true)]
public void QuotationList(string labelno)
{
if (HttpContext.Current.Session["BranchId"].ToString() == null)
{
Server.Transfer("Index.aspx");
return;
}
var quotation = new List<QuotationModel>();
string constr = cn.ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
qryFillGrid = " select ItemType from tbl_StockRunning stock " + System.Environment.NewLine;
var cmd = new SqlCommand(qryFillGrid, con);
con.Open();
var dr = cmd.ExecuteReader();
while (dr.Read())
{
var quotationModel = new QuotationModel
{
ItemType = dr[0].ToString().Trim()
};
quotation.Add(quotationModel);
}
}
var js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(quotation));
}
Now, when I am doing alert of alert(JSON.stringify(data));
then I am getting value in correct Like [{“ItemType”:”GOLD”}] format. But when I am doing alert(JSON.stringify(data.ItemType));
then it getting undefined