日期:2014-05-16  浏览次数:20660 次

ajax提交表单

示例代码如下:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="js/jquery.min.js?v=<?php echo time;?>"></script>
    <script type="text/javascript" src="js/jquery.form.js?v=<?php echo time;?>"></script>
  </head>

  <body>
     <form id="myForm" action="comment.php" method="post">
      Name: <input type="text" name="name" />
      Comment: <textarea name="comment"></textarea>
     <input type="submit" value="Submit Comment" />
    </form>


      <script type="text/javascript">
         // wait for the DOM to be loaded
          $(document).ready(function() {
             // bind 'myForm' and provide a simple callback function
            // use ajaxSubmit  direct submit 
          $('#myForm').ajaxForm(function() {
                 alert("Thank you for your comment!");
             });
         });
     </script>
  </body>
</html>
?