Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将数据从一个表单发布到两个不同的url_Javascript_Php_Ajax_Arrays_Forms - Fatal编程技术网

Javascript 将数据从一个表单发布到两个不同的url

Javascript 将数据从一个表单发布到两个不同的url,javascript,php,ajax,arrays,forms,Javascript,Php,Ajax,Arrays,Forms,如何从一个表单向两个不同的url发送帖子 例如,在同一时间将POST name发送到process.php和confirm.php $(document).ready(function(){ $("#myform").validate({ debug: false, rules: { name: "required", email: { required: true,

如何从一个表单向两个不同的url发送帖子

例如,在同一时间将POST name发送到process.php和confirm.php

$(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执行此操作:

给提交按钮一个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! 
          }              
      }
     });
  });
});

$(文档).ready(函数(){
//当用户单击Submit时,post开始
$(“#发送”)。单击(函数(){
//获取输入字段名值
var vNAME=$(“#name”).val();
//首先将其发送到process.php
$.ajax({
类型:“post”,
url:“process.php”,
数据:{name:vNAME},
数据类型:“json”,
成功:功能(数据){
//如果process.php收到post数据并正确处理,则返回
//成功消息否则,返回错误消息。
if(data.success==“true”){
…成功消息!
}否则{
…不成功的消息!
}              
}
});
//发送到confirm.php
$.ajax({
类型:“post”,
url:“confirm.php”,
数据:{name:vNAME},
数据类型:“json”,
成功:功能(数据){
//如果process.php收到post数据并正确处理,则返回
//成功消息否则,返回错误消息。
if(data.success==“true”){
…成功消息!
}否则{
…不成功的消息!
}              
}
});
});
});

如果取消表单的正常提交,并通过AJAX发出这两个请求,则只能这样做。但无论如何,在大多数情况下,人们问这样的问题,他们已经走错了方向——所以请先描述一下你真正想要实现的目标。