My ajax isn't working out. I have a form that I'm submitting through ajax to my php file, to update my database. It's updating the database correctly, however there must be something wrong with my ajax. The problem is it always calls my .fail function even when successful and it's not reseting the values of the input fields. Please, take a look:
$(".myForm").submit(function(e) {
e.preventDefault();
var url = "myurl.php";
$.ajax({
type: "POST",
url: url,
data: $(this).serialize()
}).done(function() {
alert("Success");
$('#email').value='';
}).fail(function() {
alert("Fail!");
});
});
It's giving me a fail alert, but my database is updating. What did I do wrong?
EDIT: My php is returning a result and I edited my code like this. My ajax looks like this now, but I'm still getting same error
$(".myForm").submit(function(e) {
e.preventDefault();
var url = "http://fullyawaken.com/website/database/updatedatabase.php";
$.ajax({
type: "POST",
url: url,
data: $(this).serialize(),
statusCode: {
200: function(){
alert("Success!");
$('#email').val("");
}
}
}).fail(function() {
$('#email').val("");
alert("Fail!");
});
});