0

我在 $.ajax 函数中有 json 响应,我也可以提醒整个响应,但是如何在“recordFound”函数下提醒特定字段作为响应,例如名字。

JSON 响应

{"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");
            });

        });

    });

ASP.NET-MVC 控制器发送 JSON

 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);
            }
4

1 回答 1

0

我找到了以下答案;

var paraed = JSON.parse(data.Response);

alert(paraed.Title + "   "+paraed.FirstName);
于 2015-08-03T09:31:54.083 回答