前端開發記錄

1、ajax請求後this所指會變,導致數據渲染不出來。。。

let _this = this

2、最近接受JQ+Bootstrap項目改造,記錄遇到的問題

     需求:接口請求加token      bootstrap文件需添加token(  bootstrap-table.js )添加:

beforeSend: function (res) {

         res.setRequestHeader("token", localStorage.getItem('token'));

},

request = $.extend({}, calculateObjectValue(null, this.options.ajaxOptions), {
            type: this.options.method,
            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,
            beforeSend: function (res) {                
                res.setRequestHeader("token", localStorage.getItem('token'));
            },
            success: function (res) {
                res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);

                that.load(res);
                that.trigger('load-success', res);
            },
            error: function (res) {
                that.trigger('load-error', res.status, res);
            },
            complete: function () {
                if (!silent) {
                    that.$tableLoading.hide();
                }
            }
        });

 

 

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