Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets Google工作表中Javascript中未定义的返回_Google Sheets - Fatal编程技术网

Google sheets Google工作表中Javascript中未定义的返回

Google sheets Google工作表中Javascript中未定义的返回,google-sheets,Google Sheets,为什么我会从这段代码中得到一个未定义的结果 index.html <div> <input type="text" id="emp_name" placeholder="Employee Name" > <p id="en"></p> </div> <script> $( document ).ready(function() { $( "#submit_password" ).submit(fu

为什么我会从这段代码中得到一个未定义的结果

index.html

<div>
  <input type="text" id="emp_name" placeholder="Employee Name" >
  <p id="en"></p>
</div>
    <script>
  $( document ).ready(function() {
    $( "#submit_password" ).submit(function() {
      google.script.run.withSuccessHandler(function(ret){
        $( "#thank_you" ).show();
        $("#submit_password").slideUp();
        console.log(ret);
      }).sendPassword(this); 
      reloadSite();
    });
    getEmployeeName();
  }); 

function getEmployeeName(){
    alert(google.script.run.getEmployeeName());
    document.getElementById('emp_name').value = google.script.run.getEmployeeName();
    var name = google.script.run.getEmployeeName();
    document.getElementById("en").innerHTML = name;
  }
<script>

但在我的日志中,我得到了预期的结果。非常感谢您的帮助。

代码是异步运行的,可能还没有完成执行,结果还未定义

尝试添加到HTML

function suc(x) {
  return x;
}
然后

document.getElementById('emp_name').value = 
    google.script
          .run
          .withSuccessHandler(suc)
          .getEmployeeName();
document.getElementById('emp_name').value = 
    google.script
          .run
          .withSuccessHandler(suc)
          .getEmployeeName();