|
<html> |
|
|
|
<head> |
|
<style> |
|
table, |
|
th, |
|
td { |
|
margin: 10px 0; |
|
border: solid 1px #333; |
|
padding: 2px 4px; |
|
font: 15px Verdana; |
|
} |
|
|
|
th { |
|
font-weight: bold; |
|
} |
|
|
|
#loader { |
|
border: 16px solid #f3f3f3; |
|
border-radius: 50%; |
|
border-top: 16px solid blue; |
|
border-bottom: 16px solid blue; |
|
width: 60px; |
|
height: 60px; |
|
-webkit-animation: spin 2s linear infinite; |
|
animation: spin 2s linear infinite; |
|
visibility: hidden; |
|
} |
|
|
|
@-webkit-keyframes spin { |
|
0% { |
|
-webkit-transform: rotate(0deg); |
|
} |
|
|
|
100% { |
|
-webkit-transform: rotate(360deg); |
|
} |
|
} |
|
|
|
@keyframes spin { |
|
0% { |
|
transform: rotate(0deg); |
|
} |
|
|
|
100% { |
|
transform: rotate(360deg); |
|
} |
|
} |
|
</style> |
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> |
|
<script> |
|
var script_url = "YOUR_APPS_SCRIPT_URL"; |
|
|
|
// Make an AJAX call to Google Script |
|
function insert_value() { |
|
$("#re").css("visibility", "hidden"); |
|
document.getElementById("loader").style.visibility = "visible"; |
|
$('#mySpinner').addClass('spinner'); |
|
|
|
var id1 = $("#id").val(); |
|
var name = $("#name").val(); |
|
|
|
|
|
var url = script_url + "?callback=ctrlq&name=" + name + "&id=" + id1 + "&action=insert"; |
|
|
|
|
|
var request = jQuery.ajax({ |
|
crossDomain: true, |
|
url: url, |
|
method: "GET", |
|
dataType: "jsonp" |
|
}); |
|
|
|
} |
|
|
|
function update_value() { |
|
$("#re").css("visibility", "hidden"); |
|
document.getElementById("loader").style.visibility = "visible"; |
|
var id1 = $("#id").val(); |
|
var name = $("#name").val(); |
|
var url = script_url + "?callback=ctrlq&name=" + name + "&id=" + id1 + "&action=update"; |
|
var request = jQuery.ajax({ |
|
crossDomain: true, |
|
url: url, |
|
method: "GET", |
|
dataType: "jsonp" |
|
}); |
|
} |
|
|
|
function delete_value() { |
|
$("#re").css("visibility", "hidden"); |
|
document.getElementById("loader").style.visibility = "visible"; |
|
$('#mySpinner').addClass('spinner'); |
|
var id1 = $("#id").val(); |
|
var name = $("#name").val(); |
|
var url = script_url + "?callback=ctrlq&name=" + name + "&id=" + id1 + "&action=delete"; |
|
var request = jQuery.ajax({ |
|
crossDomain: true, |
|
url: url, |
|
method: "GET", |
|
dataType: "jsonp" |
|
}); |
|
} |
|
|
|
// print the returned data |
|
function ctrlq(e) { |
|
$("#re").html(e.result); |
|
$("#re").css("visibility", "visible"); |
|
read_value(); |
|
} |
|
|
|
function read_value() { |
|
$("#re").css("visibility", "hidden"); |
|
document.getElementById("loader").style.visibility = "visible"; |
|
var url = script_url + "?action=read"; |
|
|
|
$.getJSON(url, function (json) { |
|
// Set the variables from the results array |
|
|
|
// CREATE DYNAMIC TABLE. |
|
var table = document.createElement("table"); |
|
|
|
var header = table.createTHead(); |
|
var row = header.insertRow(0); |
|
var cell1 = row.insertCell(0); |
|
var cell2 = row.insertCell(1); |
|
|
|
cell1.innerHTML = "<b>ID</b>"; |
|
cell2.innerHTML = "<b>Name</b>"; |
|
|
|
// ADD JSON DATA TO THE TABLE AS ROWS. |
|
for (var i = 0; i < json.records.length; i++) { |
|
|
|
tr = table.insertRow(-1); |
|
var tabCell = tr.insertCell(-1); |
|
tabCell.innerHTML = json.records[i].ID; |
|
tabCell = tr.insertCell(-1); |
|
tabCell.innerHTML = json.records[i].NAME; |
|
} |
|
|
|
// FINALLY ADD THE NEWLY CREATED TABLE WITH JSON DATA TO A CONTAINER. |
|
var divContainer = document.getElementById("showData"); |
|
divContainer.innerHTML = ""; |
|
divContainer.appendChild(table); |
|
document.getElementById("loader").style.visibility = "hidden"; |
|
$("#re").css("visibility", "visible"); |
|
}); |
|
} |
|
</script> |
|
</head> |
|
|
|
<body> |
|
<div align="center"> |
|
<h1>CRUD OPERATION ON GOOGLE SPREAD SHEET, WEB APPLICATION USING GOOGLE APP SCRIPT .</h1> |
|
<p>This is simple application, You can develop your own logic based on your requiremnets.<p> |
|
<p>Be careful with the parameters you are sending, it should match the parameters that are recived in google app script.</p> |
|
|
|
<form> |
|
ID |
|
<input type="text" name="id" id="id"> |
|
Name |
|
<input type="text" name="name" id="name"> |
|
</form> |
|
|
|
<div id="loader"></div> |
|
|
|
<p id="re"></p> |
|
|
|
<input type="button" id="b1" onClick="insert_value()" value="Insert"></input> |
|
<input type="button" onclick="read_value()" value="Read" /> |
|
<input type="button" onclick="update_value()" value="Update" /> |
|
<input type="button" onclick="delete_value()" value="Delete" /> |
|
<a href="YOUR_SPREADSHEET_LINK" |
|
target="_blank">Click here to open Spread Sheet </a> |
|
<div id="showData"></div> |
|
</div> |
|
</body> |
|
<html> |
hi bro, you get any solution please reply