$('#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 。