我想調用一個webmethod並獲取json對象並在jquery中顯示aspx文件中的數據。但有些事情是錯誤的,它不起作用。我將下面jquery無法讀取json對象並顯示數據
代碼解釋這裏是將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 + "\"}]";
}
,這裏是jQuery代碼。
$('#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);
});
}
});
});
我想提醒()返回什麼,但它不顯示任何內容。我非常確定,我可以從數據庫中獲取數據並正確分析它。...
我的代碼有什麼問題?我怎樣才能做到顯示json對象?
你檢查數據,看數據是否存在? – karthick 2013-03-07 11:31:25
顯示你的json結果。 – 2013-03-07 11:31:26
也發佈您的數據對象... – bipen 2013-03-07 11:31:53