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

后端 未结 3 1838
情书的邮戳
情书的邮戳 2021-02-07 08:31

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         


        
3条回答
  •  春和景丽
    2021-02-07 09:14

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

提交回复
热议问题