4

I created a function that do an ajax call but I have this error when I call my GetTempData method in C# :

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 :

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

user2274060
  • 896
  • 5
  • 18
  • 35

2 Answers2

21

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. Try calling your GetTempData method again. You will see an entry in the network tab that corresponds to the GetTempData request and is highlighted in red. If you click on that you will be able to see detailed information about your request and response.

enter image description here

HTH

Teppic
  • 2,506
  • 20
  • 26
0

processData: false, cache: false,

you ignore these attributes in ajax, if you pass object data to the controller in MVC POST method, at that time you can use these attributes.but in get method is not working, simply you use the get method

thanks

Milad Hatami
  • 1,494
  • 13
  • 18
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 13 '22 at 13:10