我正在尝试在Google云端硬盘上托管的html中使用jquery和datatables。数据表的数据将使用内容服务从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/测试工具中正常工作。 应用程序脚本发布给任何人,甚至是匿名的。 用实际表替换apps脚本调用会产生工作页面。
答案 0 :(得分:3)
大约1。 你应该发布jsonp请求。因为Google Apps脚本不会添加“Access-Control-Allow-Origin”标头。
关于2.
Google Apps脚本的身份验证始终返回html页面, 如果用户未登录。
如果你需要处理登录状态,你应该在jsonp请求上处理它。
如果您只想允许访问域或组用户,您应该将'我''执行应用程序设置为'并通过Session.getActiveUser()。getEmail()检查用户电子邮件地址,但它只能是应用帐户
这是我的类似应用程序,它在客户端使用angularjs,但也许只是成为你的提示。
https://plus.google.com/u/1/112329532641745322160/posts/1EpJUYP7mfm
答案 1 :(得分:0)
使用javascript控制台(Chrome中的Ctrl
+ Shift
+ J
)查找您遇到的错误。搜索错误。获取this page。请注意,它表示你必须在你的桌子里面。添加以下内容而不是您当前的表。
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1</td>
<td>Row 2</td>
<td>Row 3</td>
<td>Row 4</td>
<td>Row 5</td>
</tr>
</tbody>
</table>
您可以在应用脚本中使用Session.getActiveUser()
来确定是谁在运行脚本,并从那里决定是否返回数据,或者不返回数据。