从谷歌文档发送跨域HTTP-POST

时间:2017-01-13 16:44:23

标签: javascript http-post google-docs-api google-sheets-api

我需要通过其他网站上的google脚本从google docs传递POST请求。只要单元格发生变化,就必须发送请求。请求应包含来自不同单元的信息。我创建了链接,但我无法发送。

function onEdit(e){
  // Set a comment on the edited cell to indicate when it was changed.
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var range = e.range;
  // var to sent
  var wait = 'wait'; // status
  var approve = 'approve'; // status
  var decline = 'decline'; // status
  var amount = 990; // price
  var sec = 'a1atugqv'; // ID to server
  var vcode = sheet.getRange(range.getRow(), 9).getValue(); // ID clients` click
  var orderID = sheet.getRange(range.getRow(), 2).getValue(); // ID order
  // end
  var listItem = e.value; // Value drop-down cell, wich edit
  //var xhr = new XMLHttpRequest(); I tried using this transfer. It did not work
  var url = 'http://example.com/common.php?vcode=' + vcode + '&amount=' + amount + '&order_id=' + orderID + '&sec=' + sec + '&status=';
  if ((listItem == 'new') || (listItem == 'mobile off') || (listItem == 'send')){
    var response = UrlFetchApp.fetch('http://www.example.com/'); // I tried using this transfer. It did not work
    // i should send POST or GET here. With new status
    //var site = url + wait;
    //var resData = UrlFetchApp.fetch(site);
  } else if ((listItem == 'approve') || (listItem == 'send') || (listItem == 'ok')){
    // i should send POST or GET here. With new status
    range.setNote('approve'); // check
    //xhr.open('GET', url + approve, true);
    // xhr.send();
  } else if ((listItem == 'decline') || (listItem == 'return')){
    range.setNote('decline');
    //xhr.open('GET', url + decline, true);
    // xhr.send();
  }
}

0 个答案:

没有答案