簡體   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