I am sending data using AJAX POST. The data is JSON format. See below. However, I keep getting 'Unexpected token u in JSON at position 0'. Why is this happening? The reason I am setting contentType here is so that the Boolean field checked does not get converted to string.
var data = { "user": "tom", "number": 9, "checked": false } $.ajax({ url: url, method: "POST", data: data, contentType: 'application/json', dataType: 'json', beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password)); }, success: function (success) { console.log("success"); } });
contentType: 'application/json'and the backend is treating the Boolean like a string, so I read that I should set it to avoid this issue. Which I did, and now it won't even get sent to the backend server