Reputation: 1
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
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
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
Reputation: 74202
Use $.post
:
$.post(
'read.php',
{
'name': $('input[name="name"]').val()
}
);
Upvotes: 0
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