繁体   English   中英

在单个页面中使用Ajax和php进行多表单数据上传

[英]multiple form data upload using ajax and php in single page

我的疑问是如果我有

这些div标签是使用jquery通过过渡效果隐藏的,我想在结果中获取div 1 2 3的结果

1 div
  <div id="1">    
   </div>      
2 div
   <div id="2">
    </div>       
3 div
   <div id="3">
   </div>
   <input type="submit" name="first-sudmit" value="NEXT" onclick="result(this.value)" />
    </div>
    <div id="result">   
        result    
    </div>

在js中:

<script type="text/javascript">
function showResult()    
{
    alert("dfadsfdasf");
    xmlhttp.open("GET","result.php?q="+str,true);
    xmlhttp.send();
}
</script>

而且我什至尝试了序列化tooo .....没有运行php脚本

喜欢

js:

<script type="text/javascript">     
function showFormData(oForm) {
   var msg = "The data that you entered for the form with 'name' attribute='" + oForm.name + "': \n";

  submitHandler: function(form) {
                // do other stuff for a valid form
                $.post('result.php', $("#submit_drop,#submit_radio,#submit_check,#submit_text,#submit_drag_text,#submit_drag_img").serialize(), function(data) {
                 $('#results').html(data);
            });           
   alert(msg);
}  
</script>

的PHP:

   //page1 process
    if(!ekpty($_POST['first-submit']))
    {
        $first1=$_POST['drop1'];
        $first2=$_POST['drop2'];
        $first3=$_POST['drop3'];
        $first4=$_POST['drop4'];
        $first5=$_POST['drop5'];
      for(i=0;i<=4;i++)
      {         
          $sql="INSERT INTO $score1(correct)VALUES('$first[i]')";        
      }                
    }
    else
    {
          print '<script type="text/javascript">'; 
          print 'alert("page 1 no answer is attempted")'; 
          print '</script>'; 
    }
//output resu;ts
$sql="SELECT count(chkpt) from score1 where chkpt='1'";    
echo $sql;

所以现在如何在最后一个结果div标签中获取这些表格的结果。

请一些回答。

您的问题有点难以理解,但是如果我理解您的要求,我相信您的序列化代码会起作用,但是我相信您需要使用包含要序列化元素的表单ID。 所以:

1 div
  <div id="1">
     <form id="firstFormToSubmit">......</form>
   </div>      
2 div
   <div id="2">
     <form id="secondFormToSubmit">......</form>
    </div>       
3 div
   <div id="3">
    <form id="thirdFormToSubmit">......</form>
   </div>
   <input type="submit" name="first-sudmit" value="NEXT" onclick="result(this.value)" />
    </div>
    <div id="result">   
        result    
    </div>

然后处理这些形式:

submitHandler: function(form) {
            // do other stuff for a valid form
            $.post('result.php', $("#firstFormToSubmit").serialize(), function(data) {
             $('#results').html(data);
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM