I have seen this question has been asked so many times, but please try to understand what is my actual problem.
My JavaScript codes are :
$.ajax({
type: "POST",
url: 'ScheduleCampiagn.aspx/GetTemplate',
data: '{TempId: ' + $('#<%=ddl_Select_Template.ClientID%>').val() + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response);
},
failure: function (response) {
}
});
And my GetTemplate function in ScheduleCampiagn.aspx.cs is:
[System.Web.Services.WebMethod]
public static List<TemplateClass> GetTemplate(int TempId)
{
List<TemplateClass> dataTemp = new List<TemplateClass>();
TemplateClass temp = new TemplateClass();
String cmd = "Select Tmpl_Id,Tmpl_Body_Content from TBL_DESIGN_TEMPLETE WHERE Tmpl_Id='" + TempId + "'";
DataSet dsTemp = new DataSet();
dsTemp.Clear();
con.Retrive(cmd, ref dsTemp);
cmd = string.Empty;
temp.TempId = Convert.ToInt32(dsTemp.Tables[0].Rows[0]["Tmpl_Id"]);
temp.TempContent = Convert.ToString(dsTemp.Tables[0].Rows[0]["Tmpl_Body_Content"]);
dataTemp.Add(temp);
return dataTemp;
}
The GetTemplate function returns only one row as I Expected. But my problems are:
1.when it is executing alert box shown with content as [object Object].
2.when i change the success function as alert(response[0].TempId); it shows that response is undefiend
3.i also debug the js code with FireBug It is showing ReferenceError: response is undefiened.
4.i also tried with response.d to get the value, but it is not working.
I only want to fetch the content of dataTemp i:e
1.dataTemp.TempId
2.dataTemp.TempContent
Please help me on this or kindly let me know what i have missed in these code, I have already lost 1 whole day by searching it.
Thank you very much
console.loginstead ofalertto see what the actual object contains - then in the firebug console you can see the object. You can also see the object in the network tab > find the ajax call > look at the responsejsonfrom yourwebmethodas you ajax is expecting the same...