我正在尝试将值从我的jquery传递到我在GS中的duplicateFoldersAndFiles函数,通过在GS上调用generateFolderTree函数来检索这些值并且它工作正常,但是当我调用duplicateFoldersAndFiles时我得到一个错误NetworkError:Connection failure由于HTTP 0,我的值也没有通过。我该如何解决这个问题? 这是我的代码。谢谢!
jquery的
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
var destFolder = false;
var canClick = true;
var text;
var textDest;
$(function(){
$("#selectFolder").click(runMyFunction);
});
function runMyFunction(){
if(canClick){
google.script.run
.withSuccessHandler(successCallback)
.withFailureHandler(showError)
.generateFolderTree();
canClick = false;
}
}
function showError(error) {
console.log(error);
window.alert('An error has occurred, please try again.');
}
function onSuccess() {
console.log( "text " + text + " other " + textDest);
}
function successCallback(returnedArray)
{
console.log("returnedArray" + returnedArray);
var folders = returnedArray;
console.log("folders" + folders);
var i = 0;
//row;
for( i=0; i<folders.length;i++)
{
console.log("i = " + i);
var row = $('<p><tr><button class = "selectedFolder">' + folders[i] + '</button></tr></p>');
$("#source").append(row.html());
}
}
$('#source').on('click', 'button.selectedFolder', function(){
if (!destFolder){
text = $(this).text();
$('#sourceFolder').text(text);
}
else{
textDest = $(this).text();
$('#destinationFolder').text(textDest);
}
});
$('#destFolder').on('click', function(){
destFolder = true;
$('#source').empty();
//alert('boof');
google.script.run
.withSuccessHandler(successCallback)
.withFailureHandler(showError)
.generateFolderTree();
});
$('#copy').on('click', function(){
//alert('boof');
google.script.run
.withSuccessHandler(onSuccess)
.withFailureHandler(showError)
.duplicateFoldersAndFiles(text, textDest);
});
</script>
code.gs
function duplicateFoldersAndFiles(text, textDest) {
var ui = SpreadsheetApp.getUi();
var mySource = text;
var myDestination = textDest;
ui.alert(mySource);
}