在同一页面中使用ajax成功引导联系人表单

在同一页面中使用ajax成功引导联系人表单,ajax,forms,twitter-bootstrap,Ajax,Forms,Twitter Bootstrap,我有这个: <form role="form" method="post" action="validar.php" data-toggle="validator"> <h2>¿Te interesa?<br> Nosotros te llamamos</h2> <div class="form-group">

我有这个:

            <form role="form" method="post" action="validar.php" data-toggle="validator">
            <h2>¿Te interesa?<br>
            Nosotros te llamamos</h2>
            <div class="form-group">
                 <label for="Nombre">Nombre*</label><input data-error="Debes facilitarnos tu nombre" class="form-control" id="Nombre" name="Nombre" type="text" required />
                 <div class="help-block with-errors"></div>
            </div>
            <div class="form-group">
                 <label for="Empresa">Empresa</label><input class="form-control" id="Empresa" name="Empresa" type="text">
            </div>
            <div class="form-group">
                 <label for="Correo">Correo electrónico*</label><input data-error="Debes facilitarnos tu correo electrónico" class="form-control" id="Correo" name="Correo" type="email" required />
                 <div class="help-block with-errors"></div>
            </div>
            <div class="form-group">
                 <label for="Telefono">Teléfono</label><input class="form-control" id="Telefono" name="Telefono" type="tel">
            </div>
            <div class="form-group">
                 <label for="Horario">Qué día y hora prefieres</label><input class="form-control" id="Horario" name="Horario" type="text">
            </div>                 
          <button type="submit" class="btn btn-image" name="send"><span style="position:relative;top: -20px;">Solicitar información</span></button>
            <div class="checkbox">
                 <label><input type="checkbox" required /><a target="_blank" href="http://www.trisquel.com/privacidad/">Acepto las condiciones</a></label>
            </div>
        </form>

有兴趣吗?
拉马莫斯诺索特罗斯酒店 名义* 埃普雷萨酒店 科雷奥电气公司* 特莱福诺酒店 奎迪亚·霍拉·普雷弗雷斯 信息律师
php重新收集所有数据(POST)并发送和发送电子邮件

我想添加ajax/jquery代码,当用户在与表单相同的页面中单击“提交”并在索引页面中执行validar.php时,在提交按钮下方显示一条success消息(f.e:Thxs for all!)

谢谢

//这是表单的id
$(“#idForm”).submit(函数(){
var url=“validar.php”;//处理表单输入的脚本。
$.ajax({
类型:“POST”,
url:url,
数据:$(“#idForm”).serialize(),//序列化表单的元素。
成功:功能(数据)
{
$(“消息”)。文本(“成功消息”);
}
});
return false;//避免执行表单的实际提交。
});

有兴趣吗?
拉马莫斯诺索特罗斯酒店 名义* 埃普雷萨酒店 科雷奥电气公司* 特莱福诺酒店 奎迪亚·霍拉·普雷弗雷斯 信息律师
使用jquery序列化表单并发布。为您的表单提供一个id,以便您可以引用它(如myForm)

然后用Ajax调用发布它(阅读jQueryAjax文档)

在Ajax调用的成功回调中,执行以下操作

$('#contactDiv').hide();
$('#successDiv').show();

因此,您需要在表单周围创建一些div,在成功消息周围创建另一个div。

但不要显示任何内容:(,他应该显示“成功消息”当用户单击submit时,表单元素被序列化?有什么问题吗?我是否向validar.php添加了一些代码?是否调用了您的php文件?您从php文件返回了什么?电子邮件是否发出?
$('#contactDiv').hide();
$('#successDiv').show();