【发布时间】:2016-03-31 04:47:59
【问题描述】:
不从 C# 控制器操作返回 AJAX 成功
我已经尝试了许多可用的选项,但它仍然没有将数据返回到 AJAX 成功可能是什么原因?
我想返回列表Listemr_t_Immunization从控制器的动作到我的AJAX调用的成功数据我应该怎么做
请看下面的代码谢谢
AJAX 请求
$.ajax(
{
url: '@Url.Action("getmedi", "Immunization")',
type: 'Post',
async: false,
contentType: 'application/json',
dataType: "json",
data: JSON.stringify({ "patient2": patient2}),
success: function (data) {
debugger
$(data).each(function(index, element){
$('#first > tbody').append('<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>');
$('#first > tbody > tr:last-child > td:nth-child(1)').append('<input id='+element.ImmunizationId+' value='+element.VaccineName+'>');
$('#first > tbody > tr:last-child > td:nth-child(2)').append('<input id='+element.Immunization_Id+' value='+element.DateGiven+'>');
$('#first > tbody > tr:last-child > td:nth-child(3)').append('<input id='+element.Immunization_Id+' value='+element.Route+'>');
})
$("input[name='VaccineName']").attr('disabled', 'disabled');
$("input[name='DateGiven']").attr('disabled', 'disabled');
$("input[name='Route']").attr('disabled', 'disabled');
},
error: function (textStatus, errorThrown)
{
debugger
}
});
控制器动作
[HttpPost]
public JsonResult getmedi(int patient2)
{
if (patient2.ToString() != "")
{
string roster = objOrgCont.getmedi(patient2);
JavaScriptSerializer ser = new JavaScriptSerializer();
emr_t_Immunization erx = (emr_t_Immunization)ser.Deserialize(roster, typeof(emr_t_Immunization));
List<emr_t_Immunization> Listemr_t_Immunization = db.emr_t_Immunization.Where(Allemr_t_Immunization => Allemr_t_Immunization.Patient_Id == patient2).ToList();
///List<emr_t_Medical_History> Listemr_t_Medical_History2 = (from Allemr_t_Medical_History in db.emr_t_Medical_History where Allemr_t_Medical_History.Mr_No == Mr_No select Allemr_t_Medical_History).ToList();
if (erx != null)
{
//return Json(new { success = true, for_Date = erx.Med_Date, for_Name = erx.Name, for_Active = erx.Active, for_Resolved = erx.Resolved, for_Comments=erx.Comments });
return Json(new { Listemr_t_Immunization, JsonRequestBehavior.DenyGet });
}
}
return Json(new { success = false });
}
我也尝试在返回之前对其进行字符串化,但它显示以下错误
我用过
return JsonConvert.SerializeObject(Listemr_t_Immunization);
现在它给了我错误
使用类型检测到自引用循环 'System.Data.Entity.DynamicProxies.as_t_appointment_305685F58BEE75BAC95975F9457412A0DE58BB59D3EDBD1155C7DB5E21A7BA66'。 小路 '[0].erx_t_patient.as_t_appointment[0].erx_t_city.as_t_appointment'
【问题讨论】:
-
你的意思是每次出现错误回调??
-
我要返回列表
Listemr_t_Immunization -
return Json(new { Listemr_t_Immunization, JsonRequestBehavior.AllowGet });试试看
-
您现在的实际问题是什么?更新您的原始帖子以更了解您想要做的事情,我会尽力帮助您
-
好的,我会更新,但我想返回列表
Listemr_t_Immunization以取得成功dataAJAX 调用我应该怎么做