2016-04-30 119 views
0

主要目的是让数据在excel中变化并将数据返回给某个URL,这样我就可以将数据更新到数据库中。ajax返回值到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; 
    } 
} 
+0

可能重复[如何返回来自异步调用的响应?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-打电话) – RRK

+1

我几乎不知道这个人问什么。 –

+0

我想你需要在ajax调用中指定数据选项。像数据:{dataChanged:hot.getDataAtRow(source [0] [0])},如果需要发送更改的数据 – daremachine

回答

0

我想你需要在你的代码做一些修改,如果你想将其转换后发布在服务器上的数据。首先你转换它然后发送到服务器。

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.stringify(a)将数组转换为json格式并将其发布到服务器上。