rain_man_johny
rain_man_johny

Reputation: 1

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

Upvotes: 0

Views: 136

Answers (5)

GordonM
GordonM

Reputation: 31730

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

Upvotes: 0

Naveed
Naveed

Reputation: 42093

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;
  });
 });

Upvotes: 1

Vamsi Krishna B
Vamsi Krishna B

Reputation: 11490

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

and make the form with the id ajax-form

Upvotes: 0

Alan Haggai Alavi
Alan Haggai Alavi

Reputation: 74202

Use $.post:

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

Upvotes: 0

Kyle
Kyle

Reputation: 2872

Check out the documentation and look for the example "Save some data to the server and notify the user once it's complete."

Upvotes: 0

Related Questions