邮政数据从一种形式到2个不同的网址 [英] Post data from one form to 2 different url

查看:391
本文介绍了邮政数据从一种形式到2个不同的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何能够从一种形式发出后2个不同的网址

How i can send post from one form to 2 different url

像发送POST名process.php和confirm.php在同一个时代

Like send POST name to process.php and confirm.php in the same times

$(document).ready(function(){
    $("#myform").validate({
        debug: false,
        rules: {
            name: "required",
            email: {
                required: true,
                email: true
            }
        },
        messages: {
            name: "Please let us know who you are.",
            email: "A valid email will help us get in touch with you.",
        },
        submitHandler: function(form) {
            // do other stuff for a valid form
            $.post('process.php', $("#myform").serialize(),     function(data) {
                $('#results').html(data);
            });
        }
    });
});`    

和我的表格

<form name="myform" id="myform" action="confirm.php" method="POST"> 

<label for="name" id="name_label">Name</label>  
<input type="text" name="name" id="name" size="30" value=""/>  
<br>
<label for="email" id="email_label">Email</label>  
<input type="text" name="email" id="email" size="30" value=""/> 
<br>
<input type="submit" name="submit" value="Submit"> 

感谢您的帮助

推荐答案

嗯,如果我知道,你想从你的形式发送输入名称值到两个不同的PHP文件一次? 您可以通过使用jQuery做到这一点:

Well, if I understood, you want to send the input name value from your form to two different PHP files at once? You can do this by using jquery:

举一个ID提交按钮

<input type="submit" name="submit" id="send" value="Submit"> 

$(document).ready(function(){
     //When the user click on Submit, the post starts

     $("#send").click(function(){
     //get the input field name value
     var vNAME = $("#name").val();

     //send it first to process.php
     $.ajax({
      type: "post",
      url: "process.php",
      data: {name: vNAME},
      dataType: "json",
      success: function(data){
          //if process.php receive the post data and process right, it returns
          //a message of success otherwise, return a error message.
          if(data.success=="true"){
             ... successful message! 
          }else{
             ... unsuccessful message! 
          }              
      }
     });

     //sending to confirm.php
     $.ajax({
      type: "post",
      url: "confirm.php",
      data: {name: vNAME},
      dataType: "json",
      success: function(data){
          //if process.php receive the post data and process right, it returns
          //a message of success otherwise, return a error message.
          if(data.success=="true"){
             ... successful message! 
          }else{
             ... unsuccessful message! 
          }              
      }
     });
  });
});

这篇关于邮政数据从一种形式到2个不同的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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