简体   繁体   中英

jquery form submitting

index.php

<form method="post" action="read.php">
    <p>Name: <input type="text" name="name" value="" /></p>
    <p><button type="submit">Okay</button></p>
</form>

i'd like to send name value to read.php without refreshing the page. i wanna use jquery. but how?

Edit: i want to make this job without refreshing the page. well, i tried every examples, and they sent me to read.php after pressing the okay button. i dont wanna go to read.php.

edit2: lol, we can't send a value to another page without refreshing the page :) such a shame for us. lol

Download jQuery and include it in your application.

 $(document).ready(function(){     
   jQuery('form').live('submit',function(event) {
      $.ajax({
          url: $(this).attr('action'),
          type: 'POST',
          data: $(this).serialize(),
          success: function( response ) {
              alert(response);
          }
      });
      return false;
  });
 });

Use the ajax forms plugin. http://jquery.malsup.com/form/

查阅文档 ,查找示例“将一些数据保存到服务器并在完成后通知用户”。

Use $.post :

$.post(
    'read.php',
    {
        'name': $('input[name="name"]').val()
    }
);

$(document).ready(function(){ $("#ajax-form").submit(function(){ $.post( "/read.php", $("#ajax-form").serialize(), ); }); });

and make the form with the id ajax-form

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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