繁体   English   中英

Ajax 调用“加载资源失败:服务器响应状态为 500”

[英]Ajax call with a 'failed to load resource : the server responded with a status of 500'

我创建了一个 function 来执行 ajax 调用,但是当我在 C# 中调用 GetTempData 方法时出现此错误:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) 

这是我的代码:

function restoreDatas() {
        $.ajax({
            url: "/AddRecipe/GetTempData",
            type: 'GET',
            dataType: 'json',
            contentType: 'application/json',
            cache: false,
            processData: false,
            success: function (result) {

            }
        });
    }

ajax调用调用的C#方法:

public ActionResult GetTempData()
    {
        return Json(
        new
        {
            title = Session["title"],
            cookingTime = Session["cookingTime"],
            preparationTime = Session["preparationTime"],
            IngredientList = Session["IngredientList"],
            ingredientsDescription = Session["ingredientsDescription"],
            nbPersons = Session["nbPersons"],
            Category = Session["Category"],
            difficulty = Session["difficulty"],
            nbStars = Session["nbStars"],
            file = Session["file"]
        }, JsonRequestBehavior.AllowGet
            );
    }

我看不出问题出在哪里?

你有什么解决办法?

谢谢

在浏览器中打开开发人员工具,查看请求/响应。 例如,在Chrome中按F12以打开开发人员控制台并前往“网络”标签。 尝试再次调用GetTempData方法。 您将在网络选项卡中看到与GetTempData请求对应的条目,并以红色突出显示。 如果点击它,您将能够看到有关您的请求和响应的详细信息。

在此输入图像描述

HTH

处理数据:假,缓存:假,

你忽略了 ajax 中的这些属性,如果你在 mvc POST 方法中将 object 数据传递给 controller,那么你可以使用这些属性。

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM