PUT Ajax request

前端 未结 3 2324
天涯浪人
天涯浪人 2021-02-20 09:59

I am new to doing Ajax request and have put together the following Pastie. Line 107 is my $.PUT and is throwing an error in firebug that $.PUT does not a function. As for the aj

相关标签:
3条回答
  • 2021-02-20 10:21

    You have an error here (the success function must be anonymous):

    return 
        jQuery.ajax({
            type: 'PUT',
            url: 'slot_days/show',
            data: data,
            success: function addCell() {
    
            }
        });
    

    Should be:

    function _ajax_request(url, data, callback, method) {
        return jQuery.ajax({
            url: url,
            type: method,
            data: data,
            success: callback
        });
    }
    

    and to extend jQuery:

    jQuery.extend({
        put: function(url, data, callback) {
            return _ajax_request(url, data, callback, 'PUT');
    }});  
    

    and a sample usage example:

    $.put('/url', { 'foo': 'bar' }, function(result) {
        // do something with the results of the AJAX call
    });
    
    0 讨论(0)
  • 2021-02-20 10:26

    See the simple and clean answer here: https://stackoverflow.com/a/11549679/916632 Just change the type value to "PUT".

    Also handles the 415 response that might be causing problems for others (it blocked me). Also the 400 response in terms of the data object sent.

    0 讨论(0)
  • 2021-02-20 10:32

    Seems like you're not including the _ajax_request_PUT.js in your main file. This is why the function $.put cannot be found. Include it first, then your error will disappear.

    0 讨论(0)
提交回复
热议问题