Huỳnh Tùng
Huỳnh Tùng

Reputation: 79

Send data to google script web app periodically

I am doing a small google script web app to update data from google sheet every 30 minutes. I've tried to use page refresh method but it is impossible because the web app show a blank page whenever refresh. So, is there any way to reload web app data periodically?

<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <!-- Latest compiled JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
    <meta http-equiv="refresh" content="1"> <!--this reload blank page-->
</head>

<body>
    <div><b class="alert alert-danger">SẮP HẾT NHỰA</b>
    </div>
    <div class="ggsheetdata">
    </div>
    <script>
    </script>
</body>

</html>

Upvotes: 0

Views: 107

Answers (1)

Cooper
Cooper

Reputation: 64100

You can use the Javascript setInterval function to call a Javascript Function which in turn calls a google.script.run.withSuccessHandler(function(data){//update data here}).getData();

where getData() is a Google Apps Script function that returns the required data back the SuccessHandler.

However, your webapp must be able to be running in the browser at all times for this to work.

setInterval

Upvotes: 2

Related Questions