Rai*_*l24 13 ajax jquery json put
I've looked around and tried many different methods, but can't seem to pass actual data to my controller's function.
Here is some code:
var URL = "/Timesheet/Timesheet/UpdateEntry";
var dataObject = { 'newWeekEntry': newEntry, 'oldWeekEntry': oldEntry };
alert(JSON.stringify(dataObject));
$.ajax({
url: URL,
type: 'PUT',
data: JSON.stringify(dataObject),
dataType: 'json',
success: function(result) {
alert("success?");
}
});
Run Code Online (Sandbox Code Playgroud)
newEntry and oldEntry are both objects.
The alert line outputs this (with some properties removed, just for brevity):
{"newWeekEntry":{"MondayHours":2,"TuesdayHours":2,"WednesdayHours":5,"ThursdayHours":5,"FridayHours":"4","SaturdayHours":0,"SundayHours":0},"oldWeekEntry":{"MondayHours":2,"TuesdayHours":2,"WednesdayHours":5,"ThursdayHours":5,"FridayHours":2,"SaturdayHours":0,"SundayHours":0}}
Run Code Online (Sandbox Code Playgroud)
When I debug my controller action ("UpdateEntry"), the two parameters are filled with the TimesheetEntry class default parameters (0).
我是否正确地传递了这个?
$.ajax({
url: window.serverUrl + 'student/event/' + eventId,
type: 'put',
data: JSON.stringify(data),
headers: {
'x-auth-token': localStorage.accessToken,
"Content-Type": "application/json"
},
dataType: 'json'
})
Run Code Online (Sandbox Code Playgroud)
这对我有用