jquery Google Form Response无法在网站上运行

nle07wnf  于 2023-08-04  发布在  jQuery
关注(0)|答案(2)|浏览(109)

我使用一个谷歌表单值与我的网站,我想提交的形式和存储在谷歌表作为形式的响应数据集成。我使用 AJAX 重定向到另一个页面,而不是谷歌表单提交页面。但是每当我试图提交时,它会准确地重定向到我的页面,但数据不会保存在Google Sheet中。
下面是我的代码:

<strong>Full Name</strong>
<input type="text" name="Fullname" class="form-control" id="Fullname" />
<strong>Email Address</strong>
<input type="text" name="Email" class="form-control" id="Email" />
<strong>Subject</strong>
<input type="text" name="Subject" class="form-control" id="Subject" />
<strong>Details</strong>
<textarea name="Details" rows="8" cols="0" class="form-control" id="Details"></textarea><br />
<button type="button" id="btnSubmit" class="btn btn-info" onclick="postContactToGoogle()">Submit</button>

<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
    function postContactToGoogle() {
        var email = $('#Email').val();
        var fullname = $('#FullName').val();
        var subject = $('#Subject').val();
        var details = $('#Details').val();
        $.ajax({
            url: "https://docs.google.com/forms/d/abcdefgh1234567xyz/formResponse",
            data: {
                "entry_805356472": fullname,
                "entry_1998295708": email, "entry_785075795":
                subject, "entry_934055676": details
            },
            type: "POST",
            dataType: "xml",
            statusCode: {
                0: function () {
                    window.location.replace("Success.html");
                },
                200: function () {
                    window.location.replace("Success.html");
                }
            }
        });
    }
</script>

字符串
如何在Google Sheet中保存数据?我的代码中缺少了什么吗?

hgncfbus

hgncfbus1#

您可以直接从google view form页面复制表单,如演示中所示,然后在 AJAX 调用中进行以下更改,如下图所示。现在,一旦你提交数据,它就可以在谷歌表单中看到,查看回复。

$(function(){
    $('input:submit').on('click', function(e){
      e.preventDefault();

        $.ajax({
            url: "https://docs.google.com/forms/d/18icZ41Cx3-n1iW7yTOZdiDx9a6mySWHOy9ryd1l59tM/formResponse",
            data:$('form').serialize(),
            type: "POST",
            dataType: "xml",
            crossDomain: true,
            success: function(data){
              //window.location.replace("youraddress");
              //console.log(data);
            },
            error: function(data){
              //console.log(data);
            }
        });
    });
  });

个字符

wdebmtf2

wdebmtf22#

如果你在Google上打开你的表单,点击“查看实时表单”,然后查看表单上的源代码,你会看到你想要上传的字段在表单entry.12345678中有一个name; id的形式为entry_12345678。您需要使用name值。试试这个:

<script>
    function postContactToGoogle() {
        var email = $('#Email').val();
        var fullname = $('#FullName').val();
        var subject = $('#Subject').val();
        var details = $('#Details').val();
        $.ajax({
            url: "https://docs.google.com/forms/d/abcdefgh1234567xyz/formResponse",
            data: {
                "entry.805356472": fullname,
                "entry.1998295708": email, 
                "entry.785075795":  subject, 
                "entry.934055676": details
            },
            type: "POST",
            dataType: "xml",
            statusCode: {
                0: function () {
                    window.location.replace("Success.html");
                },
                200: function () {
                    window.location.replace("Success.html");
                }
            }
        });
    }
</script>

字符串

相关问题