I am trying to call a webmethod and get json object and display the data in aspx file with jquery. but something s wrong and it is not working. I will explain with the code below
here is the webmethod
Database db = DatabaseFactory.CreateDatabase("Connection String2");
DbCommand dbCommand;
dbCommand = db.GetStoredProcCommand("MedBul_Select_Selected_Professional");
db.AddInParameter(dbCommand, "id", DbType.Int16, Convert.ToInt16(id));
IDataReader dr = db.ExecuteReader(dbCommand);
if(dr.Read())
{
int p_id = Convert.ToInt16(dr["ProfessionalID"].ToString());
string firstname = dr["ProfessionalName"].ToString();
string lastname = dr["ProfessionalSurname"].ToString();
int prefix = Convert.ToInt16(dr["PrefixID"].ToString());
int gender = Convert.ToInt16(dr["Gender"].ToString());
string birthdate = dr["BirthDate"].ToString();
string mobilephone = dr["MobilePhone"].ToString();
string email = dr["Email"].ToString();
string diplomano = dr["DiplomaNo"].ToString();
return_str += "[{\"id\":\"" + p_id + "\",\"firstname\":\"" + firstname + "\",\"lastname\":\"" + lastname + "\",\"prefix\":\"" + prefix + "\",\"gender\":\"" + gender + "\",\"birthdate\":\"" + birthdate + "\",\"mobilephone\":\"" + mobilephone + "\",\"email\":\"" + email + "\",\"diplomano\":\"" + diplomano + "\"}]";
}
and here is the jquery code.
$('#btn_second').click(function () {
//$('#txt_isim_4').val('test arif');
$.ajax({
type: "POST",
url: "Registration.aspx/get_selected_professional",
data: "{'id':'2'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$.each(data, function (index, value) {
alert(value);
alert(value.d);
alert(index);
alert(value.firstname);
});
}
});
});
I am trying to alert() what is returned but It doesnt display anything. I am very sure that I can get the data from Database and parse it properly....
What is wrong with my code? How can I get it done to display the json object?