jQuery Ajax PUT with parameters

后端 未结 4 1333
后悔当初
后悔当初 2020-12-08 04:12

It seems that using jQuery Ajax POST will pass parameters, but PUT will not. I looked at the current jQuery code and PUT and DELETE are not there. I looked at 1.4.2 jQuery

4条回答
  •  没有蜡笔的小新
    2020-12-08 04:38

    You can use the PUT method and pass data that will be included in the body of the request:

    let data = {"key":"value"}
    
    $.ajax({
        type: 'PUT',
        url: 'http://example.com/api',
        contentType: 'application/json',
        data: JSON.stringify(data), // access in body
    }).done(function () {
        console.log('SUCCESS');
    }).fail(function (msg) {
        console.log('FAIL');
    }).always(function (msg) {
        console.log('ALWAYS');
    });
    

提交回复
热议问题