How to implement a PUT call with JSON data using AJAX and JQuery? How to implement a PUT call with JSON data using AJAX and JQuery? json json

How to implement a PUT call with JSON data using AJAX and JQuery?


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.


$.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});