html - 传输或处理此请求时出错。错误代码 = 10,路径 = /wardeninit
问题描述
我正在尝试将对象(工作表行的内容)传递给应用程序脚本模板。您可以在屏幕截图中看到该行。
我在应用程序脚本中的函数包含:
var sendableRows = rows.filter(function (row) { //ONLY CHECKED ROWS.
return row['Index'] == true;
});
var sendableRow = sendableRows[0];
Logger.log('sendableRow '+ JSON.stringify( sendableRow));
var html = HtmlService.createTemplateFromFile('RowPopup');
html.row = JSON.stringify(sendableRow);
var h =html.evaluate();
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(h, 'Create Documents');
记录器语句产生:
sendableRow {"Index":true,"Timestamp":"2019-02-12T21:09:14.000Z","FROM":222222,"CONVERSATION":"THIS IS A TEST","ME":"","relativeRow":14,"absoluteRow":15}
我的 Rowpopup.html 是:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
// Prevent forms from submitting.
function preventFormSubmit() {
var forms = document.querySelectorAll('forms');
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener('submit', function(event) {
event.preventDefault();
});
}
}
window.addEventListener('load', preventFormSubmit);
function handleFormSubmit(formObject) {
// the output from form goes to processDocBuildHtml
google.script.run
.withSuccessHandler(updateUrl)
.processRowPopupHTML(formObject);
}
function updateUrl(url) {
var div = document.getElementById('output');
div.innerHTML = '<a href="' + url + '">Sent!</a>';
}
</script>
</head>
<body>
<form id="myForm" onsubmit="handleFormSubmit(this)">
<div>
<label for="optionList">Click me</label>
<select id="optionList" name="email">
<option>Loading...</option>
</select>
</div>
<br>
<div>
</div>
<br>
<div>
<textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>
</div>
<div id="textboxes"></div>
<div id="insert"></div>
<input type="submit" value="Submit" />
</form>
<div id="output">
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//rawgithub.com/indrimuska/jquery-editable-select/master/dist/jquery-editable-select.min.js"></script>
<link href="//rawgithub.com/indrimuska/jquery-editable-select/master/dist/jquery-editable-select.min.css" rel="stylesheet">
<script>
function getConversations() {
var jsonRow = <?= row ?>; //PASSED IN JSON
console.log('row');
var myObj = JSON.parse(jsonRow);
console.log(myObj['CONVERSATION']);
return myObj['CONVERSATION'];
}
</script>
</body>
当我运行它时,我看到:
这表明“监狱长”存在一些问题。
此外,我没有看到输出到控制台的预期数据:
console.log('row');
var myObj = JSON.parse(jsonRow);
console.log(myObj['CONVERSATION']);
我究竟做错了什么?
解决方案
您的客户端代码从不调用getConversations
,这就是您在控制台上看不到它的原因。在许多方法中,您可以通过在<script>
标签之间添加以下内容来添加 IIFE 来调用该函数
(function (){getConversations()}());
另一方面,即使使用最简单的代码,Chrome 开发人员工具控制台上的引用错误消息也会出现,如下所示
function myFunction(){
var html = HtmlService.createHtmlOutputFromFile('index');
SpreadsheetApp.getUi().showModalDialog(html, 'Test')
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
Hello world!
</body>
</html>
所以不是你,是谷歌
推荐阅读
- python - 如何按值对多个列执行有序选择
- php - 如何使用php将paytm API响应信息存储在mysql数据库中
- wpf - 如何使 WPF 窗口跨 4 个屏幕?
- linux - D-Bus 是中间件 IPC 吗?
- javascript - TypeError:无法读取未定义的属性“消息”
- azure - 分析 Microsoft 聊天机器人负载测试结果 (Application Insights)
- ubuntu - 无法在远程服务器上运行 Luminus 项目
- php - 根据php中的特殊字符集对数组进行排序
- user-interface - 如何在颤动中获得相对于屏幕尺寸的小部件尺寸?
- android - 当 chrome 在 android 上遇到下载链接时如何启动我的下载器应用程序?