我知道有些人提出同樣的問題並得到解答。我已經看過所有這些,但我仍然無法解決我的問題。我有一個jQuery snipet發送值給處理程序,處理程序處理來自JS的值並將數據作爲JSON數據返回。 JSON數據有兩組記錄(來自數據庫的兩行)需要通過getJSON來捕獲並處理它。 JSON數據看起來就像是
[{"Name":"P1","Description":"pd1",Value":"S1Test1"},{"Name":"P1","Description":"pd1","Value":"L1Test1"}]
我的JS是
$(document).ready(function() {
$.getJSON('ProfileHandler.ashx', { 'ProfileName': 'P1' }, function (data) {
alert(data.Name);
});
});
和我的處理程序代碼是
string ProfileName = context.Request["ProfileName"];
GetProfileDataService GetProfileDataService = new BokingEngine.MasterDataService.GetProfileDataService();
IEnumerable<ProfileData> ProfileDetails = GetProfileDataService.GetList(new ProfileSearchCriteria { Name = ProfileName });
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
string serProfileDetails = javaScriptSerializer.Serialize(ProfileDetails);
context.Response.ContentType = "text/json";
context.Response.Write(serProfileDetails);
什麼是方法錯誤嗎?
你給了我比我問的更多,感謝隊友。 – Sandy 2013-03-07 08:43:35
@Sandy Np,很高興幫助 – Johan 2013-03-07 09:09:14