2017-05-19 6 views
0

Ich habe 2 Formulare auf einer Seite. Ein zum Hochladen von Bildern und andere zum Hochladen von Spezifikationen.JQuery Formular senden Mehrere Male/

Problem Ich habe ein Problem mit meiner Ajax-Anfrage, die Formularanforderung mehrmals gesendet. Wenn ich auf "Bild hochladen" klicke, wird das gleiche Bild wie bisher hochgeladen. Dadurch wird das Klickereignis gespeichert und jedes Mal zum neuen Ereignis hinzugefügt.

Ich versuchte, dies unter Verwendung .unbind() zu beheben; es funktioniert Allerdings, wenn ich Upload-Spezifikation klicken, wird es die Upload-Bildanforderung ausführen. Also .Unbind() hat nicht funktioniert.

Wie kann ich das bitte beheben. Also wird die richtige Ajax-Anfrage nur einmal gesendet.

Hier ist Code für meinen Bildupload.

//IMAGE UPLOAD 
    $(document).unbind('submit').bind('submit', "#UploadImage",function() { 

     event.preventDefault(); 

     var customerId = $(this).parent().find('input[name="customerId"]').val(); 
     var image = $(this).parent().find('input[name="image"]').val(); 

     //send ajax request 
     jQuery.ajax({ 
     url: "../data/stock.php?action=stock-image-upload", 
     type: "POST", 
     data: new FormData(this), 
     processData: false, //prevent jQuery from converting your FormData into a string 
     contentType: false, 
     success: function(data, textStatus, jqXHR) { 
     console.log(2); 
      $('.image-viewer-modal').modal('hide'); 
      var filter = "<?php echo $id_stc ?>"; 
      var tab_content_to_change = "#stock-sub-list"; 
      jQuery(tab_content_to_change).load('/tasks/stock/stock-list.php?filter='+filter); 


     }, 
      error: function(jqXHR, textStatus, errorThrown){ 
      //Display error message to user 
      alert("An error occured when saving the data"); 
     } 
    }); 
}); 

Hier ist die Spezifikation hochladen.

//specification UPLOAD 
    $(document).unbind('submit').bind('submit', "#Uploadspecification ",function() { 

     event.preventDefault(); 

     var customerId = $(this).parent().find('input[name="customerId"]').val(); 
     var specification = $(this).parent().find('input[name="specification "]').val(); 

     //send ajax request 
     jQuery.ajax({ 
     url: "../data/stock.php?action=stock-specification -upload", 
     type: "POST", 
     data: new FormData(this), 
     processData: false, //prevent jQuery from converting your FormData into a string 
     contentType: false, 
     success: function(data, textStatus, jqXHR) { 
     console.log(2); 
      $('.image-viewer-modal').modal('hide'); 
      var filter = "<?php echo $id_stc ?>"; 
      var tab_content_to_change = "#stock-sub-list"; 
      jQuery(tab_content_to_change).load('/tasks/stock/stock-list.php?filter='+filter); 


     }, 
      error: function(jqXHR, textStatus, errorThrown){ 
      //Display error message to user 
      alert("An error occured when saving the data"); 
     } 
    }); 
}); 

, wie ich das Ereignis so wird jedes Mal einreichen löschen kann ich auf Upload-Button klicken, rechts Ajax-Anforderung nur einmal

Vielen Dank im voraus gesendet.

Antwort

0

versuchen mit Async: false oder anderen Ende Sie keine von einer Veranstaltung nach Klick auf einmal

+0

klicken kann ich versuchte nur, dass es immer noch mehr als eine Anforderung sendet. –