I am trying to send the null data by JQuery AJAX. However, I end up getting an error message which says "Bad Request". I have tried using the word "null" to send to the database, however, this has not worked. The database does allow for nulls. I can manually add data directly into the database while inputting no data in the null columns.
$.ajax({
method: 'POST',
url: 'http://localhost:58371/api/ScheduleDateAndTime',
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
"startDateAndTime": startTotalTimeAndDate,
"endDateAndTime": endTotalTimeAndDate,
"studentId": studentIdSelected,
"staffId": staffIdSelected
}),
success: function (data) {
alert("You have assigned staff member " + staffSelected + " to student " + studentSelected + " on " + datePickerValue + " starting at " + startTime + " and ending at " + endTime);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError + " have you checked that you have selected a date in the calander?\n Please ensure all fields have been correctly entered");
}
});
I want to be able to send null data on the "studentId" column in the database. "studentId" is a variable that gets its data from a drop-down list, where one of the available options is "none", which has "null" as its id.
nullfor that value, then it sounds like your ASP logic is not configured correctly to allow nulls. In that case you would need to amend the ASP code, not your JS. Also, be sure that you're sending an actualnullvalue, not the word in a string, eg'null'.