1. 程式人生 > >bootstrapTable post 方式請求資料 (注意POST大小寫)

bootstrapTable post 方式請求資料 (注意POST大小寫)

$('#table').bootstrapTable({
	url:'...', 
        method: 'post',       
        queryParams: function (params) {
	             return param;
        }...	

下面貼出bootstrapTable 原始碼,一看便知

 request = $.extend({}, calculateObjectValue(null, this.options.ajaxOptions), {
            type: this.options.method,
            url:  url || this.options.url,
            data: this.options.contentType === 'application/json' && this.options.method === 'post' ?
                JSON.stringify(data) : data,
            cache: this.options.cache,
            contentType: this.options.contentType,
            dataType: this.options.dataType,
            success: function (res) {
                res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);
 
                that.load(res);
                that.trigger('load-success', res);
                if (!silent) that.$tableLoading.hide();
            },
            error: function (res) {
                that.trigger('load-error', res.status, res);
                if (!silent) that.$tableLoading.hide();
            }
        });

data引數設定時,如果是大寫的POST 則傳遞json物件引數,如果是小寫post則傳遞 json字串;

要實現 bootstrapTable 將js物件json串post到 服務端,除了將method設定為 post(小寫)外,還需 將contentType設定為 "application/json";後端接收方法中引數物件加上 @RequestBody  。

參考:https://blog.csdn.net/TxnZks/article/details/78206283