ajax将值返回到url

ajax return value to url

本文关键字:url 返回 ajax      更新时间:2023-09-26

主要目的是在excel中获取更改后的数据,并将数据返回到某个URL,这样我就可以将数据更新到数据库中。

我得到了更改数据的值,更改的数据是一个数组。

如何将它们传递到响应并返回到URL

这是代码:

afterChange: function(source, changes) {
    var a;
    if (changes !== 'loadData') {
        $.ajax({
            async: false,
            url: 'url.com',
            dataType: 'json',
            success: function(res) {
                //get data changed at row
                a = hot.getDataAtRow(source[0][0]);
                res = a;
                //console shows the value of res was changed to a;
                console.log(res);
            }
        });
        return a;
    }
}

如果您想在转换后将数据发布到服务器上,我认为您需要对代码进行一些修改。首先转换数据,然后将其发送到服务器。

afterChange: function(source, changes) {
    var a;
    if (changes !== 'loadData') {
        a = hot.getDataAtRow(source[0][0]);
        postDataToServer(a);
    }
}
function postDataToServer(a){
$.ajax({
            async: false,
            url: 'url.com',
            data: a,// JSON.stringify(a), if 'a' is an array
            dataType: 'json',
            success: function(res) {
                console.log(res);
            }
        });
}

您的数据是JSON格式的吗?若并没有,那个么您可以使用json.stringfy(a)将数组转换为json格式,并将其发布到服务器上。