【问题标题】:Ajax form with post method带有 post 方法的 Ajax 表单
【发布时间】:2021-11-15 11:09:26
【问题描述】:

AJAX 表单不想工作,它会引发错误。单击按钮并刷新所有数据时,我需要它工作。

<form name="form" id="form" class="form">
     
      <div class="field">
        <label for="input-kitId" class="label is-size-7 has-text-weight-light has-text-left">Order ID</label>
        <div class="field">
          <div class="control is-expanded">
          <input type="text" id="input-kitId" class="home-form__input input is-danger" name="number" value="" placeholder="Order ID"/>
          </div>
        </div>
      </div>
      
      <div class="field">
        <label for="input-firstName" class="label is-size-7 has-text-weight-light has-text-left">Email</label>
        <div class="field"><div class="control is-expanded">
          <input type="text" id="input-firstName" class="home-form__input input" name="email" value="" placeholder="Email"/>
          </div>
        </div>
      </div>
      <button type="submit" class="button is-midnightBlue">Generate Booking Reference</button>
    </form>        
   
<script type="text/javascript">
  $("#form").submit(function(e) {
    e.preventDefault();
    var form = $(this);
    var url = form.attr('action');
    
    $.ajax({
      crossDomain: true,
           type: "POST",
           url: 'https://www.harleymedic.co.uk/qrcodes/form.php',
           data: form.serialize(),
           success: function(data)
           {
               alert(data);
           }
         });
  
    
});

</script>

【问题讨论】:

  • 你遇到了什么错误?

标签: javascript jquery ajax


【解决方案1】:

尝试添加一个表单方法。获取或发布方法 例如:form method="post"

【讨论】:

  • 没有帮助((((
  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2019-12-08
  • 2023-04-05
  • 1970-01-01
  • 2014-01-29
  • 2016-01-02
  • 2013-10-25
  • 2017-11-16
  • 2017-07-28
  • 1970-01-01
相关资源
最近更新 更多