I have a problem with Jquery Ajax posting.
Previously I was using
<form method="post" action="manageUserItem.php">....</form>
to post my input value and insert into database.
But when I try to change to jquery ajax function with this code:
$.validator.setDefaults({
submitHandler: function() {
var formData = new FormData($(this)[0]);
$.ajax({
url:'manageUserItem.php',
type: 'POST',
data: formData,
async: false,
beforeSend: function(){
if(confirm('Are you sure?'))
return true;
else
return false;
},
cache: false,
contentType: false,
processData: false
}).done(function () {
//do something if you want when the post is successfully
if(!alert('New User Created.')){document.getelementbyclassname('form').reset()}
}).fail(function () {
//if the post is failed show an error message if you want
alert('Some error occur. Please try again later.');
});
return false;
}
});
then my input field for name, userid and password become empty when insert into the database.
Is there anything wrong in my code?
Please give me some advice, because I'm still new to this.
new FormData(this[0]);maybe.new FormData($('#yourForm'));?