2011-04-24 97 views
14

所有我想要做的是當我點擊提交我想要所有表單數據被髮送到process.php ...然後在process.php我想回顯出POST數據...然後替換一切結果div來什麼在process.php做...jQuery POST表單數據

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $("#myform").submit(function() {  
      $.ajax({ 
       type: "POST", 
       dataType: "html", 
       cache: false, 
       url: "process.php", 
       success: function(data){ 
        $("#results").html(data);      
       } 
      }); 
      return false; 
     }); 

     //$("#myform").submit(function() { 
      //$('#results').html("yay");      
     //} 
      // }); 
     //});   
    }); 
</script> 

<form name="myform" id="myform" action="" method="POST"> 
<!-- The Name form field --> 
    <label for="name" id="name_label">zoom</label> 
    <input type="text" name="zoom" id="zoom" size="30" value=""/> 
    <br> 
</select> 


<!-- The Submit button --> 
    <input type="submit" name="submit" value="Submit"> 
</form> 

<!-- FORM END ---------------------------------------- --> 


<!-- RESULTS START ---------------------------------------- --> 
    <div id="results">nooooooo<?PHP $_SESSION[''] ?><div> 
    <!-- <input type="image" name="mapcoords" border="0" src="mapgen.php"> ---- --> 
<!-- RESULTS END ---------------------------------------- --> 
+4

那麼,有什麼問題? – Nacho 2011-04-24 19:53:41

+0

你的代碼似乎這樣做(冷檢)。問題是什麼? – Halcyon 2011-04-24 19:54:05

+0

這是什麼問題? – 2011-04-24 20:04:12

回答

6
$("#myform").submit(function() {  
    $.ajax({ 
     type: "POST", 
     data : $(this).serialize(), 
     cache: false, 
     url: "process.php", 
     success: function(data){ 
      $("#results").html(data);      
     } 
    }); 
    return false; 
}); 

測試它

+0

非常適合我! – 2012-07-27 18:04:38

33

您可以撥打012通過表單數據序列化。像這樣:

<script type="text/javascript"> 
     $(document).ready(function(){ 
      $("#myform").submit(function() {  
       $.post(
       'process.php', 
       $(this).serialize(), 
       function(data){ 
        $("#results").html(data) 
       } 
      ); 
       return false; 
      }); 
     }); 
</script> 
+1

感謝工作像一個魅力 – LabRaTT 2011-04-24 20:11:47

+0

keepitterron代碼工作,但現在我想改變一件事...我有