常用的ajax请求模板

Ng4——Sass(查询列表)

 /*获取次卡列表数据*/
    getCardList(): void{
        let sendData = {
            
        };
        let connect = this._api.getApi({
            sendData: sendData,//组装前端传递参数
            type: 'get',
            apiUrl: XXXX
        });
        connect.then(res => {
            if(res.data){
                this.listData = res.data;
            }
        });
    }

Ng4——Sass(删除一条或者多条数据)

/*删除事件*/
    delCard(id: any): void{
        layer.confirm('确定要删除该次卡?', index => {
            let sendData = {
                shopId: XXX,
                cardId: id //组装前端传递参数
            };
            let connect = this._api.getApi({
                sendData: sendData,
                apiUrl: XXX,
                type: 'form'
            });
            connect.then(res => {
                if(res.data){
                    layer.msg('删除成功');
                    layer.close(index);
                    this.getCardList();
                }
            });
        });
    }

Html5常用

//一个公用的ajax模板
function loadKind() {
    let sendData = {

    };

    $.ajax({
        type: 'get',
        url : '/api/species',
        //url: '/api/one/new/list?p=1',
        data: sendData,
        dataType: 'json',
        success: function (data) {
            if (data) {
                //请求成功
            } else {
                alert(data.msg);
            }
        },
        error: function () {
            //alert("");
        }
    });
}

你可能感兴趣的:(常用的ajax请求模板)