【问题标题】:How to manipulate and redirect google form action without having that shown to the user with javascript and/or jquery如何在不使用 javascript 和/或 jquery 向用户显示的情况下操作和重定向 google 表单操作
【发布时间】:2015-09-01 22:44:41
【问题描述】:

我有一个谷歌表单,我将它嵌入到我的网站并更改 css,因此它可以发布到谷歌表格。

<form action="https://docs.google.com/forms/d/FormID/formResponse" method="POST" target="_self" onsubmit="" role="form">
  <table>
    <thead>
      <tr>
        <th>Friends name</th>
        <th>Email</th>
      </tr>
    </thead>
  <tbody>

  <tr>
    <td>
      <div class="form-group">
        <input type="text" name="entry.ID" value="" id="entry_ID" class="form-control" dir="auto" aria-label="Name  " title="">
      </div>
    </td>

    <div>
      <input type="submit" name="submit" value="Submit" id="button-submit" class="btn btn-primary btn-block">
    </div>
</form>`

现在,如果您注意到按钮是此处的输入,我想要做的是保持表单正常发布到谷歌表格,而不向用户显示任何内容,我想将用户重定向到不同的页面成功消息或一些表示发布有效的 jquery 操作。 我希望我足够具体,谷歌没有帮助,我找不到类似的东西, ps:我删除了大部分不相关的代码和输入。

【问题讨论】:

    标签: javascript jquery html forms dom-manipulation


    【解决方案1】:

    你不能让它正常发布并劫持服务器的响应。但是您可以使用 AJAX 发布数据并处理响应:

    $( "form" ).on( "submit", function( event ) {
      var $t = $( this ),
          params = $t.serialize(),
          url = $t.prop('action');
    
      event.preventDefault();
    
      $.post( url , params )
         .done(function() {
            console.log( "success" );
            window.location.href = "success.html");
         })
         .fail(function() {
            console.log( "error" );
            window.location.href = "error.html");
         });
    });
    

    【讨论】:

    • 它工作,它发布到表单,但函数返回失败,所以我被重定向到错误页面,我收到此错误 XMLHttpRequest cannot load docs.google.com/forms/d/FormID/formResponse。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问 Origin 'localhost:63342'。
    猜你喜欢
    • 2023-01-12
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    相关资源
    最近更新 更多