Force Backbone fetch to always use POST

前端 未结 1 386
感动是毒
感动是毒 2020-12-30 10:29

I have a Collection that needs to POST some data to its url to get the data it needs. The answer to these two questions, Fetch a collection using a POST request? and Overri

相关标签:
1条回答
  • 2020-12-30 11:07

    After reading the question again, here's a way to force the fetch to use POST per fetch call. (Thanks for the comments)

    yourCollection.fetch({
        data: $.param({id: 1234}), 
        type: 'POST', 
        success: function(d){
            console.log('success');
        }
    });
    

    Another approach is to override the AJAX implementation itself to use POST for all calls.

    Backbone.ajax = function() {
        var args = Array.prototype.slice.call(arguments, 0);
        _.extend(args[0], { type: 'POST' });
        return Backbone.$.ajax.apply(Backbone.$, args);
    };
    
    0 讨论(0)
提交回复
热议问题