jquery - Prevent multiple upload Ajax PHP -


currently experiencing issues multiple uploads on ajax.

i've tried:

 e.preventdefault();  e.stopimmediatepropagation(); 

in function keeps duplicating anyways. can spam submit button , multiple uploads happen. suggestions?

$(document).ready(function () {  /* data insert starts here */ $(document).on('submit', '#savepost', function (e) { e.preventdefault(); e.stopimmediatepropagation();     /* image upload ajax */     $.ajax({         url: "create.php",         type: "post",         data: new formdata(this),         contenttype: false,         cache: false,         processdata: false,         beforesend: function () {              $("#err").fadeout();         },         success: function (data) {             if (data == 'invalid file') {                 // invalid file format.                 $("#err").html("invalid file !").fadein();             } else {                  $("#dis").fadeout();             $("#dis").fadein('slow', function () {                 $("#dis").html('<div class="alert alert-info">' + data + '</div>');                 // view uploaded file.                 $("#preview").html(data).fadein();                 $("#savepost")[0].reset();                 $("body").fadeout('slow', function () {                     $("body").fadeout('slow');                     window.location.href = "memberpage.php";                  });             });             }         },         error: function (e) {             $("#err").html(e).fadein();         }     });     /* image upload ajax ending */     return false; }); /* data insert ends here */ 

use .one instead of .on

it ensures fire 1 time.

if still want submit multiple time refer this.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -