weixin_33734785 2016-04-30 10:18 采纳率: 0%
浏览 66

Ajax返回值到url

The main purpose is to get the data changed in excel and return the data to certain URL,so I can update data into database.

I've got the value of changed data,the changed data is an array.

How do I pass them to response and return to URL?

Here is the code:

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;
    }
}
  • 写回答

1条回答 默认 最新

  • DragonWar% 2016-04-30 14:19
    关注

    I thought you need to make some modification in your code if you want to post data on server after converting it. First you convert it then send it to server.

    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);
                }
            });
    
    }
    

    Is your data is in JSON format? If not then you can convert an array into json format using JSON.stringify(a) and post it on server.

    评论

报告相同问题?