首页 > 解决方案 > 返回值ajax

问题描述

function storeExportFG (dataStore) {
    var storeEx = $.ajax({
        method: 'get',
        url: window.location.origin + '/export-fg-warehouse/store',
        cache: false,
        data: dataStore,
        dataType: 'json'
    });

    return storeEx;
}
dataStore = {
    'id'    : table.row(point).data()[1],
    'number': table.row(point).data()[5],
};
storeExportFG(dataStore).done(function (data){});
storeExportFG(dataStore).fail(function (err){});

这是我的代码。我遇到的问题是这样做时,我的代码会同时两次添加到数据库中。如何打印出错误值?

标签: javascript

解决方案


试试这个方法

dataStore = {
    'id'    : table.row(point).data()[1],
    'number': table.row(point).data()[5]
};

function storeExportFG (dataStore) {
    var storeEx = $.ajax({
        method: 'get',
        url: window.location.origin + '/export-fg-warehouse/store',
        cache: false,
        data: dataStore,
        dataType: 'json'
    });

    return storeEx;
}

storeExportFG(dataStore).done(function (data){

}).fail(function (err){

});


推荐阅读