头中的脚本似乎没有执行

问题描述 投票:0回答:1

根据此博客文章[https://aws.amazon.com/blogs/architecture/create-dynamic-contact-forms-for-s3-static-websites-using-aws-lambda-amazon-api-gateway-and-amazon-ses/,我正在尝试使用带有api网关的AWS上的lambda来在静态S3网站上创建联系表单。>

我不认为我的脚本正在运行,因为我的提交按钮什么都不做。有什么想法我可能做错了吗?这是我的完整页面代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ltdrescue Contact Form</title>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<script "text/javascript">
function submitToAPI(e) {
       e.preventDefault();
       var URL = "https://abc1234.execute-api.us-east-1.amazonaws.com/01/contact";

            var Namere = /[A-Za-z]{1}[A-Za-z]/;
            if (!Namere.test($("#name-input").val())) {
                         alert ("Name can not less than 2 char");
                return;
            }
            var mobilere = /[0-9]{10}/;
            if (!mobilere.test($("#phone-input").val())) {
                alert ("Please enter valid mobile number");
                return;
            }
            if ($("#email-input").val()=="") {
                alert ("Please enter your email id");
                return;
            }

            var reeamil = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,6})?$/;
            if (!reeamil.test($("#email-input").val())) {
                alert ("Please enter valid email address");
                return;
            }

       var name = $("#name-input").val();
       var phone = $("#phone-input").val();
       var email = $("#email-input").val();
       var desc = $("#description-input").val();
       var data = {
          name : name,
          phone : phone,
          email : email,
          desc : desc
        };

       $.ajax({
         type: "POST",
         url : "https://abc1234.execute-api.us-east-1.amazonaws.com/01/contact",
         dataType: "json",
         crossDomain: "true",
         contentType: "application/json; charset=utf-8",
         data: JSON.stringify(data),


         success: function () {
           // clear form and show a success message
           alert("Successfull");
           document.getElementById("contact-form").reset();
       location.reload();
         },
         error: function () {
           // show an error message
           alert("UnSuccessfull");
         }});
     }
    </script>   
    </head>

<body>
<div id="wrap">
    <div class="top_corner"></div>
    <div id="main_container">

        <div id="header">
            <div id="logo"><a href="index.html"><img src="images/logo.gif" alt="" title="" border="0" /></a></div>

            <a href="make-a-donation.html" class="make_donation"></a>

            <div id="menu">
                <ul>                                                                                            
                    <li><a href="default.html" title="">Home</a></li>
                    <li><a href="about.html" title="">About</a></li>
                    <li><a href="adopt.html" title="">Adopt</a></li>
                    <li><a href="volunteer.html" title="">Support Us</a></li>
                    <li><a href="resources.html" title="">Resources</a></li>
                    <li><a class="current" href="contact.html" title="">Contact</a></li>
                </ul>
            </div>


        </div>


        <div class="center_content_pages">

              <div class="financial-application-form">
             <h2>Contact Us</h2>

             <p>
Please use this form to contact us with any suggestions or questions.  
                           <br><br>
                 <b>Note:</b> due to the ever increasing number of animals in dire need of rescue, we are unable to intake owner surrenders.
             </p>
        <form id="contact-form" method="post">
      <h4>Name:</h4>
      <input type="text" style="height:35px;" id="name-input" placeholder="Enter name here…" class="form-control" style="width:100%;" /><br/>
      <h4>Phone:</h4>
      <input type="phone" style="height:35px;" id="phone-input" placeholder="Enter phone number" class="form-control" style="width:100%;"/><br/>
      <h4>Email:</h4>
      <input type="email" style="height:35px;" id="email-input" placeholder="Enter email here…" class="form-control" style="width:100%;"/><br/>
      <h4>How can we help you?</h4>
      <textarea id="description-input" rows="3" placeholder="Enter your message…" class="form-control" style="width:100%;"></textarea><br/>
      <div class="g-recaptcha" data-sitekey="6Lc7cVMUAAAAAM1yxf64wrmO8gvi8A1oQ_ead1ys" class="form-control" style="width:100%;"></div>
      <button type="button" onClick="submitToAPI(event)" class="btn btn-lg" style="margin-top:20px;">Submit</button>
</form>

            </div
        </div>

             <div class="testimonials">
                    <h2>Need to find a new home for your pet?</h2>
                    <p>
                        <a href="http://www.adoptapet.com" target="_blank"><img src="http://images.adoptapet.com/images/shelter-badges/Approved-Shelter_Paw-Print_Badge.png"></a>
                    </p>



             </div>

        <div class="clear"></div>
        </div>

        <div class="footer">

            <div class="footer_links">
                <a class="current" href="default.html" title="">Home</a>
                <a href="about" title="">About</a>
                <a href="adopt" title="">Adopt</a>
                <a href="volunteer.html" title="">Support Us</a>
                <a href="resources.html" title="">Resources</a>
                <a href="contact.html" title="">Contact</a>            
            </div>
        </div>


    </div>
</div>
</body>
</html>

根据此博客文章,我尝试在带有api网关的AWS上使用lambda来在静态S3网站上创建联系表单:https://aws.amazon.com/blogs/architecture/create-dynamic- contact-forms-for-s3 -...

javascript html head
1个回答
0
投票

您尚未正确添加脚本标签,请参考以下内容对其进行更正。

© www.soinside.com 2019 - 2024. All rights reserved.