我有$ .ajax函数的json响应,我也可以提醒整个响应,但是如何在“recordFound”函数下响应特定字段,例如First Name。
{"StudentID":12,"StudentNumber_UWLID":21209510,"Title":"mr","FirstName":"Adam","MiddleName":null,"LastName":"Test"}
$.ajax({
url: '@Url.Action("GetStudentRecordByID", "StudentProfile")',
type: "POST",
dataType: "JSON",
data: { _GivenStudentUWLID: StudentUWLID },
cache: false
}).done(function (data, textStatus, jqXHR) {
if (data.RecordStatus == "NotAvailable")
{
$(this).MyMessageDialog({
_messageBlockID: "_StatusMessage",
_messageContent: "<div class='warningMessage'> <h4>Given Student Cannot Be Enter As Additional Tenant.</h4> <br/> Student Need to Have their Profile Completed On Student Village Portal Before Can Be Added As Additional Tenant Within The Tendency Form! <br/><br/> Or Enter Correct Student UWL ID "+"</div>",
_messageBlockWidth: "400px"
});
}
else if(data.RecordStatus=="recordFound")
{
alert(data.Response);???????
$("#AdditionalTenent").find(".listedStudentTitle").val("dddadd");
}
}).fail(function (jqXHR, textStatus, errorThrown) {
alert("error");
});
});
});
if (_entity != null)
{
var studentObj = new StudentLimitedInfo
{
StudentNumber_UWLID = _entity.StudentNumber_UWLID,
StudentID = _entity.StudentID,
Title = _entity.Title,
FirstName = _entity.FirstName,
MiddleName = _entity.MiddleName,
LastName = _entity.LastName
};
var jsonObj = new JavaScriptSerializer().Serialize(studentObj);
return Json(new { Response = jsonObj, RecordStatus = "recordFound" }, JsonRequestBehavior.AllowGet);
}
答案 0 :(得分:0)
我发现答案如下;
var paraed = JSON.parse(data.Response);
alert(paraed.Title + " "+paraed.FirstName);