0

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;
    }
}
Smit Patel
  • 2,992
  • 1
  • 26
  • 44
peter
  • 61
  • 1
  • 2
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – rrk Apr 30 '16 at 10:23
  • 1
    I have literally no idea what this person is asking.. – Joe Thomas Apr 30 '16 at 10:41
  • i think you need specify data option in ajax call. Like a data: { dataChanged: hot.getDataAtRow(source[0][0]) }, if you need to send changed data – daremachine Apr 30 '16 at 11:48
  • data and dataType are different. data - are data send to server, dataType are data what server return back. – daremachine Apr 30 '16 at 11:52
  • You need to make another call to post the converted data to server inside the success callback of your first ajax call - see the link http://stackoverflow.com/questions/36904199/how-do-i-import-the-extracted-json-data-to-database/36929741#36929741 – Afshan Shujat Apr 30 '16 at 14:13

1 Answers1

0

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.

Afshan Shujat
  • 541
  • 4
  • 9