【问题标题】:Jquery Ajax error called调用 Jquery Ajax 错误
【发布时间】:2014-11-22 08:13:00
【问题描述】:

我在下面调用我的 ajax

function LoadAudit(value) {

    $.ajax({
        url: '/Account/GetAuditRecord/' + value,
        success: function (data) {
            $("#htmlResult").val(data.html);
        },
        error:function(data) {
            alert('error');
        },
    });
};

调用我的控制器

public JsonResult GetAuditRecord(string Id)
         {
              string html =_auditLogService.FindAllByAccount().Single(a => a.Id == Id).Comments ;
             return Json(new { html = result});
         }

哪个有效(查找数据并准备传回),但是在 jquery 中触发了错误,什么时候应该成功,我错过了什么?

【问题讨论】:

    标签: c# jquery asp.net-mvc asp.net-mvc-4 asp.net-mvc-5


    【解决方案1】:

    在ajax调用中添加dataType'JSON',如图:

    $.ajax({
         url: '/Account/GetAuditRecord/' + value,
         dataType : 'JSON',
         success: function (data) {
             $("#htmlResult").val(data.html);
         },
         error:function(data) {
             alert('error');
         },
    });
    

    并在控制器操作中更改 jsonresult,如下所示:

    return Json(new { html = result }, JsonRequestBehavior.AllowGet);
    

    【讨论】:

      【解决方案2】:

      你错过了ajax调用的数据类型

      dataType : 'json',
      

      【讨论】:

        【解决方案3】:

        更改您的 Controller 返回类型:

        return Json( new { html = result }, JsonRequestBehavior.AllowGet );
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-02-24
          • 2015-04-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-06-20
          相关资源
          最近更新 更多