【问题标题】:Error on Ajax in ASP MVC 4ASP MVC 4 中的 Ajax 错误
【发布时间】:2014-12-03 10:12:36
【问题描述】:

我有一个 asp mvc 4 应用程序,但我遇到了下一个问题:

我在控制器中有一个对 ActionResult 的 Ajax 调用:

function SetMark() {
        $.ajax({
            url: '<%=Url.Action("SelectMark", "Home")%>',
            type: 'POST',
            data: {anio:$("#anio").val()},
            success: function (data) {
                $("#marca").html(data);
            }

        });
    }

和控制器:

 [HttpPost]
    public virtual ActionResult SelectMark(string anio)
    {
        if (Request.IsAjaxRequest())
        {
            tarifData.dataTable = GetMarks(anio);

            return PartialView("_Marca", tarifData);
        }
        else
        {
            return View("Index");
        }
    }

在 localhost 中正常工作,但在服务器(服务器 2008 r2)中,所有 ajax 调用都返回 500 错误。

有人知道这个问题吗?重复,在 localhost 中正常工作。

【问题讨论】:

  • 500 错误通常是控制器异常的结果。您需要将您的方法发布为SelectMark()
  • @StephenMuecke 编辑问题。
  • 唯一看起来可能有问题的是你的方法GetMarks()
  • 你在哪里初始化tarifData? (你省略了一些代码吗?)
  • 获取标记连接数据库并返回数据

标签: .net ajax asp.net-mvc-4 asp.net-ajax


【解决方案1】:

如图所示在ajax请求中指定dataType:"html"

function SetMark() {
    $.ajax({
         url: '<%=Url.Action("SelectMark", "Home")%>',
         type: 'POST',
         dataType:'html',
         data: {anio:$("#anio").val()},
         success: function (data) {
             $("#marca").html(data);
         }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多