I have a form (for password reset) that first validates that the input is a correct email, then it should look for that email's existence in my user database开发者_如何学JAVA, and finally reset the password and email the user the new one.
I'm able to do everything, but I want to have it work without page refresh. Typically I would do this all in PHP, and if there is no such email entry in my database, it would respond back after a page refresh. The thing is, I want the file that this page is using as a POST to be able to send back data to the page without a refresh, showing an error or not.
I'm going to be using jQuery $.post()
. Any help?
Here's my jQuery post code:
$.post('php/recoverPost.php', $('#recoverPost').serialize(), function(){
$('#recoverPost').hide();
$('#success').show();
});
You could do something like this:
$('#registerform').submit(function() {
e.preventDefault();
$.ajax({
'url': 'posturl.php',
'type': 'POST',
'data': {
'email': $('#email').val(),
'username': $('#username').val()
},
'success':function(data) {
if(data == 'success') {
alert('did it!');
} else {
alert('I failed!');
}
}
});
});
if you make posturl.php echo 'success' if the e-mail doesn't exist this will work.
$("#form").submit(function(event) {
event.preventDefault();
$.post( url, ,$('#recoverPost').serialize(),
function( data ) {
$('#recoverPost').hide();
$('#success').show();
}
);
});
精彩评论