0

I have a web page made with HtmlServices. This page has a form I want to submit to a GAS web app made to behave as a web service.

When I use google app script UrlFetch to call my web service from my first GAS app, I very often get a timeout. Unfortunately we cannot set the GAS UrlFetch timeout value which I think is around 10s. 10s is not enough for a GAS app to copy a file, open/edit a spreadsheet and send an email!

So I decided to use Jquery and do an ajax post (because I can set the timeout value) within my web page built with HtmlServices. (so my page is sanitized by Google Caja). Jquery is said to be supported by Caja.

But I noticed that the Ajax URL is always rewritten to be the first web app URL (the url I want to post to is changed by Caja I assume). Seems to me that Google's Caja is preventing that Ajax call. I could not find anything on Caja / Ajax post limitations within a GAS HtmlService.

Would you have suggestions on how to call a web service from a GAS Web App, without having the limitation of the GAS timeout?

4

2 に答える 2

2

The best suggestion I can give for right now is to use JSONP instead of Ajax to make the call. You should not see timeouts in that case, and it should work fine.

于 2012-11-05T21:23:35.887 に答える
0

Couple of things

  1. AJAX calls (with jQuery or vanilla JS) from a web app deployed on script.google.com to a content service deployed on script.google.com does not work. I've confirmed this and I believe this is a security restriction. I tried a few different workarounds and this looks like there is no short term options.

  2. Regarding the server side option with UrlFetchApp. I believe the timeout is actually 30 seconds. However, that might still not be enough and it looks you are running into frequently enough.

So basically the 3rd (less optimal) option that I would recommend is a "queue" based approach. In this approach - have your HTML web app call a ScriptDb queue. Then you can have a timed trigger (every minute or every hour) that runs as you to perform the requisite operations. Just share the same script library between both scripts so you can share the script DB reference for the queue.

于 2012-11-02T22:09:05.417 に答える