How to preview image before upload?

Image preview before upload using asp.net webpages & webmatrix + Jquery

  • i've been trying to use a jquery & ajax plugin for the image preview but i cant for the life of me get it to work. This is the site I found the code/demo http://www.zurb.com/playground/ajax_upload I can get as far as changing the preview background but then no image is shown for the selected image file. this is my ,chtml file <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link href="@Href("~/Styles/jquery/jquery.ui.all.css")" rel="stylesheet" type="text/css" /> <link href="@Href("~/Styles/Site.css")" rel="stylesheet" type="text/css" /> <script src="@Href("~/Scripts/jquery-1.7.js")" type="text/javascript"></script> <script src="@Href("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script> <script src="@Href("~/Scripts/jquery.js")" type="text/javascript"></script> <script src="@Href("~/Scripts/ajaxupload.js")" type="text/javascript"></script> <script> $(document).ready(function(){ var thumb = $('img#thumb'); new AjaxUpload('imageUpload', { action: $('form#newHotnessForm').attr('action'), name: 'image', onSubmit: function(file, extension) { $('div.preview').addClass('loading'); alert(file); }, onComplete: function(file, response) { thumb.load(function() { $('div.preview').removeClass('loading'); thumb.unbind(); }); thumb.attr('src', response); } }); }); </script> </head> <body> <h2>New Hotness</h2> <div> <div class="preview"> <img id="thumb" width="100px" height="100px" src="../Images/Test.jpg" /> </div> <form id="newHotnessForm"> <label>Upload a Picture of Yourself</label> <input type="file" id="imageUpload" size="20" /> <button type="submit" class="button">Save</button> </form> </div> </body> </html>

  • Answer:

davey at Stack Overflow Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.