Here's my client-side jQuery code:
$.ajaxSetup ({
   contentType: "application/json",
   datatype: 'json'
});
$.ajax({
   type: "POST",
   url: "http://localhost:1234/path",
   data: JSON.stringify(myData),
   success: function(aString){
      alert(aString);
   },
   error: function(errorData){
      alert(errorData);
   }
});
Here is the data the server sends out:
200
Content-Type: application/json
"aStringsData"
In the alert the quotes of "aStringData" are displayed. However, I'd expect the quotes to be taken away due to the automatic JSON.parse I expect to happen from datatype: 'json'. Am I wrong on this?
The parameter is actually dataType, not datatype (JavaScript is case sensitive).
You can try with:
dataType: 'json' // not datatype
within your ajaxSetup;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With