Ajax Request returns HTTP error 500, using MVC and $.ajax call with POST?

jquery ajax 500 internal server error php
c# return error to ajax call
how to handle 500 internal server error in javascript
failed to load resource: the server responded with a status of 500 (internal server error ajax)
ajax return error response
post request 500 internal server error
jquery ajax post 500 internal server error asp net
ajax post 500 internal server error c# mvc

I've seen several threads about this, and I've tried all the answers (ASP.NET MVC JsonResult return 500)

My ajax request is re-turning a 500 Internal Error. If I debug I never even get to my action.

Here is my ajax call:

$.ajax({
                    url: '@Url.Action("UpdateSortOrder", "FormItems")',
                    data: { itemToUpdateId: item.attr("id"), newParentItemId: parentItemId, newPreviousItemId: previousItemId },
                    type: 'POST',
                    success: function (data) {
                        console.log(data);
                    },
                    error: function (xhr, status, exception) {
                        console.log("Error: " + exception + ", Status: " + status);
                    }
                });

And my action:

[HttpPost]
    public ActionResult UpdateSortOrder(Guid itemToUpdateId, Guid newParentItemId, Guid newPreviousItemId)
    {
        FormItem updatedItem = _formItemService.GetOne(x => x.Id == itemToUpdateId);

        return Json(updatedItem, JsonRequestBehavior.DenyGet);
    }

Using chrome console, these are the response headers from the reply:

HTTP/1.1 500 Internal Server Error Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNetMvc-Version: 3.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Tue, 18 Dec 2012 21:53:41 GMT Content-Length: 17041

Server logs show no substatus codes. Any idea what I am doing wrong here? I've prefer to use POST instead of GET.

The Form Data is being shown as :

itemToUpdateId:18ac5399-342e-4a39-9da1-3281a89501df

newParentItemId:null

newPreviousItemId:null

Which is correct.

I've tried setting the contentType to application/json and traditional = true like in this question: Sending ajax post to mvc with "application/json; charset=utf-8" returns error 500 from vs web developer server

Same error.

Well I was able to figure out what the problem was, there was nothing wrong with my AJAX syntax, or even the action. It was just that my returned object contained a circular reference. I was able to see the actual error in chrome console by clicking on the POST request under Network tab, then viewing the preview tab. This displayed the actual error message.

asp.net mvc, Ajax Request returns HTTP error 500, using MVC and $.ajax call with ajax post to mvc with "application/json; charset=utf-8" returns error 500  Old post, alternative answer … Just in case someone ends up here .. My issue was caused by the fact that my controller action that I was calling returned a Partial View Action Result and the PartialView .cshtml file was not being published onto the server (wasnt “included” in the Visual Studio project when publishing).

Fiddler is a great tool for catching http requests which is quite useful for debugging responses between client side and server side. Just open it when you are suspecting the problem in your browser, and when the error occur open fiddler and choose the request, then view its raw information.

[Solved] 500 Internal Server Error when pass data in $.ajax , Quote: The 500 Internal Server Error is a very general HTTP status code. It means something has gone wrong on the website and webserver is  A 500 from ASP.NET probably means an unhandled exception was thrown at some point when serving the request. I suggest you attach a debugger to the web server process (assuming you have access).

Old post, alternative answer ... Just in case someone ends up here ..

My issue was caused by the fact that my controller action that I was calling returned a Partial View Action Result and the PartialView .cshtml file was not being published onto the server (wasnt "included" in the Visual Studio project when publishing).

Returning Server-Side Errors from AJAX Calls -- Visual Studio , Returning Server-Side Errors from AJAX Calls. In ASP.NET MVC if you call an Unfortunately, all the information you typically get is the HTTP 500 error status code and it's default message. you could create your own custom error object and return it from the server Posted by Peter Vogel on 10/07/2015 at 2:20 PM  When you return value from server to jQuery's Ajax call you can also use the below code to indicate a server error: return StatusCode(500, "My error"); Or . return StatusCode((int)HttpStatusCode.InternalServerError, "My error"); Or. Response.StatusCode = (int)HttpStatusCode.InternalServerError; return Json(new { responseText = "my error" });

if you do not need updatedItem in success then do not return it just return a simple variable

Ajax call not hitting the controller action method, status 500 , Internal , My Ajax call to controller action method is not hitting the controller , it breaks in between. It says that xhr.status = 500 , response text = Internal Server Error The same code is working fine in Also, make sure that whatever handles the request is expecting the request as a GET and not a POST. One useful  Old post, alternative answer Just in case someone ends up here .. My issue was caused by the fact that my controller action that I was calling returned a Partial View Action Result and the PartialView .cshtml file was not being published onto the server (wasnt "included" in the Visual Studio project when publishing).

Ajax post request causes 500 internal server error, In short: 500 internal server error when trying to do a POST request using ajax to $currency->save(); Storage::delete($path); return 'Deleted image! press on a button with class .del-image (sending post request with ajax). Returning Server-Side Errors from AJAX Calls. In ASP.NET MVC if you call an action method on the server from JavaScript code and that action method raises an

ASP.NET MVC: Internal Server Error (500) on Action Method , This makes jQuery Ajax calls very easy to implement, as shown below. using a POST operation if your action method returns a Json result. Old post, alternative answer Just in case someone ends up here .. My issue was caused by the fact that my controller action that I was calling returned a Partial View Action Result and the PartialView .cshtml file was not being published onto the server (wasnt "included" in the Visual Studio project when publishing).

ajax post in laravel 5 return error 500 (Internal Server Error), Forum > ajax post in laravel 5 return error 500 (Internal Server Error). electricfan posted 4 years ago. Authentication Requests Input you are better off using a regular route and then doing the logic in controller using a regular MVC pattern. If I need crf token, how I'm able to generate a crf token for my ajax post request​? Gosh I spent my entire day debugging this problem, I wish I had seen your post earlier. Worked like a charm. Thank you for your tutorials and tips, they are very well done and brilliant for people like me.

Comments
  • Have you tried viewing the raw POST using Fiddler to see what is going across the wire?
  • can you share how you're setting your routes?
  • The route is working, right now it just uses the default route rule populated by adding an area. If I change the action to return a view and type in the URL, it works, so the route is processing correctly.
  • @BiffMaGriff I posted that from Chrome, but I figured it out now thanks to checking that window again, if I check the "preview" tab of the POST in chrome console, it gave me the actual error, which was the formItem being returned in the action was having a circular reference error!
  • Was able to troubleshoot similarly in IE11 Developer Tools using Network tab > Details > Response body.
  • For anyone else still having issues, check out this solution. It provides a more detailed error that Fiddler and such were not able to provide.
  • 3rd time I've Googled this gem of an answer - must commit to memory! (upvoted previously)
  • In my case I was returning a View that didn't exist when I should have been returning JSON. Boneheaded mistake that throws a 500. If you use the network tab in any browser you'll clearly see the error from asp.net.