简体   繁体   English

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

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

I created a function that do an ajax call but I have this error when I call my GetTempData method in C#:我创建了一个 function 来执行 ajax 调用,但是当我在 C# 中调用 GetTempData 方法时出现此错误:

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

This is my code:这是我的代码:

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

            }
        });
    }

The C# method called by the ajax call: 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
            );
    }

I don't see where is the problem?我看不出问题出在哪里?

Do you have any solutions?你有什么解决办法?

Thank you谢谢

Bring up the developer tools in your browser and take a look at the request / response. 在浏览器中打开开发人员工具,查看请求/响应。 For example, in Chrome press F12 to bring up the developer console and head to the Network tab. 例如,在Chrome中按F12以打开开发人员控制台并前往“网络”标签。 Try calling your GetTempData method again. 尝试再次调用GetTempData方法。 You will see an entry in the network tab that corresponds to the GetTempData request and is highlighted in red. 您将在网络选项卡中看到与GetTempData请求对应的条目,并以红色突出显示。 If you click on that you will be able to see detailed information about your request and response. 如果点击它,您将能够看到有关您的请求和响应的详细信息。

在此输入图像描述

HTH HTH

processData: false, cache: false,处理数据:假,缓存:假,

you ignore theese attributes in ajax, if you pass object data to controller in mvc POST method, at that time you can use theese attributes.but in get method is not working,simply you use get method你忽略了 ajax 中的这些属性,如果你在 mvc POST 方法中将 object 数据传递给 controller,那么你可以使用这些属性。

thanks谢谢

暂无
暂无

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

相关问题 无法加载资源:服务器使用Ajax响应状态为500 - Failed to load resource: the server responded with a status of 500 using Ajax jQuery ajax调用将无法访问控制器:无法加载资源:服务器以状态500(内部服务器错误)响应 - Jquery ajax call wont access the controller: Failed to load resource: the server responded with a status of 500 (Internal Server Error) 加载资源失败:服务器响应状态为500(内部服务器错误 - Failed to load resource: the server responded with a status of 500 (Internal Server Error 加载资源失败:服务器响应状态为 404() - Failed to load resource: the server responded with a status of 404 () 加载资源失败:服务器响应状态为500(内部服务器错误)asp.net - Failed to load resource: the server responded with a status of 500 (Internal Server Error) asp.net 无法加载资源:服务器响应状态为 500(内部服务器错误)Azure MVC - Failed to load resource: the server responded with a status of 500 (Internal Server Error) Azure MVC Ajax 调用资源加载失败:服务器响应状态为 500(内部服务器错误) - Ajax call with a failed to load resource: the server response with a status 500 (internal server error) 加载资源失败:服务器在 asp.net 内核中使用谷歌图表时响应状态为 500 () - Failed to load resource: the server responded with a status of 500 () while using google charts in asp.net core 加载资源失败:服务器响应状态为 500 () asp.net mvc - Failed to load resource: the server responded with a status of 500 () asp.net mvc 加载资源失败:服务器响应状态为 500 () | Oracle & ASP.NET 核心 MVC 3.1 - Failed to load resource: the server responded with a status of 500 () | Oracle & ASP.NET Core MVC 3.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM