Note that there are some explanatory texts on larger screens.

plurals
  1. POSend JSON to Google App Script using POST method
    primarykey
    data
    text
    <p>as the title says, I'd like to know if it's possible to send some sort of JSON to a google app script, using POST method. Once the JSON is sent, it will be handled by the google script.</p> <p>Till now, I managed to send a post request using a standard html form with 3 inputs (I followed this guide: <a href="http://mashe.hawksey.info/2011/10/google-spreadsheets-as-a-database-insert-with-apps-script-form-postget-submit-method/" rel="nofollow">http://mashe.hawksey.info/2011/10/google-spreadsheets-as-a-database-insert-with-apps-script-form-postget-submit-method/</a>). Now I'd like to move to an ajax call that send some json to the google script, but I don't know how.. </p> <p>using an ajax call like this:</p> <pre><code>$.ajax({ type: "POST", url: url, data: "someSortOfData", success: function(data){alert("ok")}, error: function(message){alert("fail")} }).done(function( msg ) { alert( "Data Saved: " + msg ); }); </code></pre> <p>where "someSortOfData" is the actual data I'm sending (I tryed with json, simple text, html, etc). Any time I run the script, the call keeps entering the "error" function, and I don't know why.</p> <p>As I told before, using a standard html form for submitting data works, so I presume the URL is fine. The problem is with the data I'm sending I think.. Maybe, server side, google script is not expecting anything different than text?</p> <p>this is how the script (Server side) looks like</p> <pre><code>function doPost(e) { var ss = SpreadsheetApp.openById(ScriptProperties.getProperty('active')); var sheet = ss.getSheetByName("DATA"); var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]; var nextRow = sheet.getLastRow(); // get next row var cell = sheet.getRange('a1'); var col = 0; for (i in headers){ val = e.parameter[headers[i]]; cell.offset(nextRow, col).setValue(val); col++; } //return sent data var app = UiApp.createApplication(); var panel = app.createVerticalPanel(); for( p in e.parameters){ panel.add(app.createLabel(p +" "+e.parameters[p])); } app.add(panel); return app; } </code></pre> <p>I probably need to edit this code too, but first I was trying to send correctly json to the server..</p> <p>What I'm doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload