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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章