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];
$.ajax({
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) {
alert(result);
},
failure: function (errMsg) {
alert(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
$.ajaxSetup({
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
Call Function Onpress React Native
Detect If User Is Using Webview for Android/Ios or a Regular Browser
Delete Row on Remove Click React
Disable/Hide Download Button in Iframe on Default Pdf Viewer
How to Refresh Form Page After Post Request
Regex in JavaScript Allow Only Numbers and One Dot Followed by Max 2 Number
How to Pass Get Request to Window.Location in JavaScript
Force Download an Image from Src Using JavaScript
How to Hide Source Code and Inspect Element Via JavaScript or Jquery
Convert/Change JavaScript Document to Jquery
How to Detect Browser Refresh Using Angular
Regex for Names Validation Allow Only Letters and Spaces
How to Get First N Number of Elements from an Array
How to Merge Two Json Object Values by Id With Plain JavaScript (Es6)
How to Remove Single Uploaded File from Jquery in Multiple File Upload
Javascript - Adding White Space to Left of String
How to Move Focus on Next Field When Enter Is Pressed
How to Add Multiple Values in Json Object and Get an Updated Json File