如何获取ajax中的选项卡形式的值到另一个php文件? [英] How to get the values of a tab form in ajax to another php file?

查看:40
本文介绍了如何获取ajax中的选项卡形式的值到另一个php文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用ajax编写了一个代码,以便在html的表单选项卡中将表单的值获取到另一个php文件email.php

I have written a code in ajax to get the values of a form in a form tab in html to another php file email.php

但是它没有在alert()中显示该消息.

But it is not showing the message in the alert().

<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
  $(function () {

    $('#contact_form1').on('sendus', function (e) {

      e.preventDefault();

      $.ajax({
        type: 'post',
        url: 'email.php',
        data: $('#contact_form1').serialize(),
        success: function () {
          alert('form was submitted');
        }
      });

    });

  });
</script>
</head>
<body>
      <div class="tabs-content">

<div tab-id="1" class="tab active">  
      <form name="contactForm1" id='contact_form1' method="post" action=''>
        <div class="form-inline">
          <div class="form-group col-sm-12 padd">
            <input type="text" class="form-control" name="name" id="exampleInputName" placeholder="name" >
          </div>
          <div class="form-group col-sm-12 padd">
            <input type="email" class="form-control" name="email" id="exampleInputEmail" placeholder="email address">
          </div>
          <div class="form-group col-sm-12 padd">
            <input type="text" class="form-control" name="telephone" placeholder="phone">
          </div>
            <div class="form-group col-sm-12 padd">
            <input type="text" class="form-control" name="Country" id="exampleInputName" placeholder="Country" >
          </div>
          <div class="form-group col-sm-12 padd">
            <textarea class="form-control" name="message" rows="3" id="exampleInputMessage" placeholder="message" ></textarea>
          </div>
        </div>
        <div class="form-group col-xs-12 padd">
          <div id='mail_success' class='success' style="display:none;">Your message has been sent successfully.
          </div>
          <div id='mail_fail' class='error' style="display:none;"> Sorry, error occured this time sending your message.
          </div>
        </div>


        <div class="form-group col-xs-8 padd" id="recaptcha2"></div>

        <div class="form-group col-sm-4 padd" id='submit'>
          <input type="submit" id='send_message' name="sendus" class="btn  btn-lg costom-btn" value="send">
        </div>
  </form>
  </div>
  </div>
</body>
</html>

我已经编写了这段代码,但是当我提交发送"按钮时,它没有显示消息表单已提交.

I have written this code but when I am submitting the send button , it is not showing the message form was submitted.

推荐答案

您错误地使用了Javascript onclick函数.

You were wrongly used the Javascript onclick function.

<script>
$(function () {

$('#send_message').on('click', function (e) {

  e.preventDefault();

  $.ajax({
    type: 'post',
    url: 'email.php',
    data: $('#contact_form1').serialize(),
    success: function (res) {
      alert('form was submitted'+res);
    }
  });

});

});
</script>

对于提交"按钮onclick仅给出.

For submit button onclick only give .

这篇关于如何获取ajax中的选项卡形式的值到另一个php文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆