我正在尝试在 Google Drive 上托管的 html 中使用 jquery 和数据表。数据表的数据来自使用内容服务的 Apps 脚本。我正在根据数据表示例进行工作。 托管的 html 是:
<title>JQUERY DataTables Page Hosted in Google Drive </title>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>JQUERY DataTables Page Hosted in Google Drive </title>
<link rel="stylesheet" type="text/css" href="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript" charset="utf8" src="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf8">
$(document).ready( function () {
$('#demo').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
$('#example').dataTable( {
"bServerSide": false,
"sAjaxSource": "https://script.google.com/macros/s/AKfycbyFGmeMnn2hlRWe1XHTgcOI4nSyi_HcJOYSg2jfBe8b-5qXPUs2/exec"
});
});
</script>
</head>
<body>
<h1>JQUERY DataTables Page Hosted in Google Drive </h1>
<p>Default dataTable with embedded data</p>
<p>Includes sorting, paging and filtering by default.</p>
<p>Entire data table loaded in one hit.</p>
<div id="demo"></div>
</body>
</html>
包含ready函数的脚本在http://live.datatables.net/中工作正常测试线束。 该应用程序脚本可以发布给任何人,甚至是匿名的。 将应用程序脚本调用替换为工作页面中的实际表格结果。
- 我需要做什么才能使其正常工作(可能存在跨域问题?)
- 给出了当前问题的解决方案......在要提交的数据对域或用户组私有(private)的情况下,我应该如何处理身份验证
最佳答案
关于1。 您应该发布 jsonp 请求。因为谷歌应用程序脚本没有添加“Access-Control-Allow-Origin” header 。
大约2。
Google Apps 脚本的身份验证始终返回 html 页面, 如果用户未登录。
如果您需要处理登录状态,您应该在 jsonp 请求上处理它。
如果您只想允许访问域或组用户,您应该设置“me”“执行应用程序为”并通过 Session.getActiveUser().getEmail() 检查用户电子邮件地址,但它只能访问应用程序帐户.
这是我的类似应用程序,它在客户端使用 angularjs,但也许只是成为你的提示。
https://plus.google.com/u/1/112329532641745322160/posts/1EpJUYP7mfm
关于使用 Apps 脚本作为源数据的 Google Drive 托管页面中的 Jquery 脚本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15355321/