Jquery Ajax Post Results in 500 Internal Server Error

Ajax - 500 Internal Server Error

The 500 (internal server error) means something went wrong on the server's side. It could be several things, but I would start by verifying that the URL and parameters are correct. Also, make sure that whatever handles the request is expecting the request as a GET and not a POST.

One useful way to learn more about what's going on is to use a tool like Fiddler which will let you watch all HTTP requests and responses so you can see exactly what you're sending and the server is responding with.

If you don't have a compelling reason to write your own Ajax code, you would be far better off using a library that handles the Ajax interactions for you. jQuery is one option.

Jquery AJAX Post: 500 (Internal Server Error)?

Your error come from your data parameter. Stringify data object instead of { 'data': data.param1 } :

var data = {};
data.param1 = words[0];

data: JSON.stringify(data),
dataType: 'application/json',
url: 'http://localhost:49242/Service.asmx/test',
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function (result) {
failure: function (errMsg) {

Your stringifyed data will result in {"param1":"Words"}, then your service should be able to bind the param1 parameter.

Ajax call results in 500 {internal server error}

Because you are referencing req.body, you need to use a router method that includes a body - post or put.

You may also need to include type: "POST" in your jQuery Ajax method.

There is a more general semantic question about whether you should use get with a query string to communicate parameters when retrieving data rather than using a request body, but that is an API design question rather than a cause of errors.

get an error `Internal Server Error [500]` when try to parsing data with ajax post

put this before this line $("#tool").droppable

headers: {
'X-CSRF-TOKEN': jQuery('meta[name="csrf-token"]').attr('content')

and put this in your head

 <meta name="csrf-token" content="{{csrf_token()}}">

Related Topics

Leave a reply