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 UR
$.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'
})
This worked for me
Use headers: {"X-HTTP-Method-Override": "PUT"}
and override the POST
request type. It works on my project...
$.ajax({
type: 'POST', // Use POST with X-HTTP-Method-Override or a straight PUT if appropriate.
dataType: 'json', // Set datatype - affects Accept header
url: "http://example.com/people/1", // A valid URL
headers: {"X-HTTP-Method-Override": "PUT"}, // X-HTTP-Method-Override set to PUT.
data: '{"name": "Dave"}' // Some data e.g. Valid JSON as a string
});
The dataType
attribute is only used when you're getting data from the server. You should be setting contentType
to application/json
when sending data to the server.