I keep getting two posts on my table when I send my create.php for a smooth upload.
$(document).ready(function () {
/* Data Insert Starts Here */
$(document).submit('submit', '#SavePost', function () {
$.post("create.php", $(this).serialize())
.done(function (data) {
$("#dis").fadeOut();
$("#dis").fadeIn('slow', function () {
$("#dis").html('<div class="alert alert-info">' + data + '</div>');
$("#SavePost")[0].reset();
$("body").fadeOut('slow', function () {
$("body").fadeOut('slow');
window.location.href = "index.php";
});
});
});
/* Image upload Ajax */
$.ajax({
url: "create.php",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
beforeSend: function () {
//$("#preview").fadeOut();
$("#err").fadeOut();
},
success: function (data) {
if (data == 'invalid file') {
// invalid file format.
$("#err").html("Invalid File !").fadeIn();
} else {
// view uploaded file.
$("#preview").html(data).fadeIn();
$("#SavePost")[0].reset();
}
},
error: function (e) {
$("#err").html(e).fadeIn();
}
});
/* Image upload Ajax ENDING */
return false;
});
/* Data Insert Ends Here */
I get one post with the image uploaded and one without. I tried to check if my post get sent twice and i have tried to delete a few lines but i can't seem to figure this one out.
Thanks!