[英]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.