come visualizzare l’anteprima di un’immagine prima e dopo il caricamento?

Ho intenzione di visualizzare l’anteprima di un’immagine o una foto in un modulo, ma non funziona e il codice HTML ha il seguente aspetto:

e incluso il codice / script JS qui sotto:

  $(document).ready(function(){ var thumb=$('#thumb'); new AjaxUpload('imageUpload',{ action:$('newHotnessForm').attr('action'), name:'image', onSubmit:function(file,extension){ $('#preview').addClass('loading'); }, onComplete:function(file,response){ thumb.load(function(){ $('#preview').removeClass('loading'); thumb.unbind(); }); thumb.attr('src',response); } }); }); 

Ci sono 2 domande principali sul mio modulo:
1. Perché l’anteprima dell’immagine o dell’immagine non funziona?
2.Come incollare la foto dal modulo quando si fa clic sul pulsante Salva, andrà / collegherà a un’altra pagina php o php che ho creato?

Prova questo: (per l’anteprima)

   
your image

Demo di lavoro qui>

la risposta di meVeekay è stata buona e sto semplicemente rendendo più improvvisato facendo 2 cose.

  1. Controlla se il browser supporta HTML5 FileReader () o meno.

  2. Consenti solo il caricamento del file immagine verificandone l’estensione.

HTML:

 

jQuery:

 $("https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#fileUpload").on('change', function () { var imgPath = $(this)[0].value; var extn = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase(); if (extn == "gif" || extn == "png" || extn == "jpg" || extn == "jpeg") { if (typeof (FileReader) != "undefined") { var image_holder = $("https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#image-holder"); image_holder.empty(); var reader = new FileReader(); reader.onload = function (e) { $("", { "src": e.target.result, "class": "thumb-image" }).appendTo(image_holder); } image_holder.show(); reader.readAsDataURL($(this)[0].files[0]); } else { alert("This browser does not support FileReader."); } } else { alert("Pls select only images"); } }); 

Per la comprensione dettagliata di FileReader ()

Controlla questo articolo: usando l’anteprima di FileReader () prima di caricare.

  https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/# https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/# the img page https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/# https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#    
https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/# https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/# the nextimg page https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/# https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#https://stackoverflow.com/questions/16207575/how-to-preview-a-image-before-and-after-upload/#

PREVIEW