0

What is the best/easiest way to post form data from my HTML page to my GAS script?

$(document).ready(function() {
  $.getJSON(SCRIPT_URL+"?callback=?", { method:"addRow"}, function (data) { alert(JSON.stringify(data)); }); 
});
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rover
  • 387
  • 4
  • 14
  • $(document).ready(function() { $.getJSON(SCRIPT_URL+"?callback=?", { method:"addRow"}, function (data) { alert(JSON.stringify(data)); }); }); I'm getting a 404 (OK) error – Rover Apr 17 '15 at 11:45
  • Lppk at the docs for doPost/doGet. Look at contentService. Come back with code and we'll help. – Zig Mandel Apr 17 '15 at 12:07
  • Second attempt, but now getting: Origin 'null' is therefore not allowed access. The response had HTTP status code 404. My permissions are all public `function writeToSpreadSheet(postData,callBack){ $.post(scripturl,postData,function(resp){ callBack(resp); }); }` – Rover Apr 17 '15 at 12:16
  • check out the answer to the following: http://stackoverflow.com/questions/27888364/get-form-input-text-value-to-insert-in-a-google-spreadsheet/27888908#27888908 – ScampMichael Apr 17 '15 at 14:40

1 Answers1

2

If you are using Apps Script HTML Service, you can use google.script.run.

Google Documentation - Client-side API - call server-side Apps Script functions

From a app or site outside of Google, make an HTTP Request to the Apps Script URL.

Alan Wells
  • 30,746
  • 15
  • 104
  • 152