2015-05-11 2 views
5

Ich lese diese: https://github.com/enyo/dropzone/wiki/Set-URL-dynamically aber i dont Erfolg habe ... :( I have 1 Form ...Wie ändere ich die URL-Dropzone? URL dynamisch mit AJAX Erfolg

Und ich sende die Eingänge mit Ajax

Die Ajax kehrt das. neue ID des Benutzers. in diesem Moment möchte ich für de url Dropzone ändern Pfad-ID des neuen Benutzers einzustellen.

$.ajax({ 
    type: "POST", 
    url: "class/inserir.php?funcao=teste", 
    data: formdata, 
    dataType: "json", 
     success: function(json){ 
     if(json.sucesso=="sim"){ 
      alert("Wait! Sending Pictures."); 
        this.options.url = "class/upload_img.php?"+json.id; 
      myDropzone.processQueue(); 
     }else{ 
     location.href="home.php?ir=cad_animal&cad=nao&erro="+json.erro; 
     } 
    } 
}); 

var myDropzone = new Dropzone("#imagens", { 

    url: "class/upload_imgteste.php", 
    paramName: "file", // The name that will be used to transfer the file 
    maxFilesize: 1, // MB 
    addRemoveLinks : true, 
    dictResponseError: "Não foi possível enviar o arquivo!", 
    autoProcessQueue: false, 
    thumbnailWidth: 138, 
    thumbnailHeight: 120, 

}); 

sorry für mein schlechtes Englisch!

Vielen Dank für alle.

Antwort

2

Änderung dieser

this.options.url = "class/upload_img.php?"+json.id; 

dieser

myDropzone.options.url = "class/upload_img.php?"+json.id; 

funktioniert das?

12

Sie können eine Funktion für den "processing" Ereignis-Listener der Dropzone hinzufügen. Hier

Dropzone.options.myDropzone = { 
    init: function() { 
    this.on("processing", function(file) { 
     this.options.url = "/some-other-url"; 
    }); 
    } 
}; 

ist der Link, wo ich den Code bekommen und es funktioniert für mich: https://github.com/enyo/dropzone/wiki/Set-URL-dynamically

1

Wenn Sie die URL Dropzone Beiträge ändern müssen, um dynamisch für jede Datei, können Sie die processingfile Ereignis und ändern verwenden die Optionen.url.

<form id="my-dropzone" action="/some-url" class="dropzone"></form> 
<script> 
Dropzone.options.myDropzone = { 
    init: function() { 
    this.on("processing", function(file) { 
     this.options.url = "/some-other-url"; 
    }); 
    } 
}; 
</script> 
Verwandte Themen