2$(document).ready(function () {
3 $('#avatar_upload_button').click(function () {
5 $('#avatar_upload').ajaxForm({
6 target: '#outputImage',
8 beforeSubmit: function () {
9 $("#outputImage").hide();
10 if($("#uploadImage").val() == "") {
11 $("#outputImage").show();
12 $("#outputImage").html("<div class='error'>Choose a file to upload.</div>");
15 $("#progressDivId").css("display", "block");
16 var percentValue = '0%';
18 $('#progressBar').width(percentValue);
19 $('#percent').html(percentValue);
21 uploadProgress: function (event, position, total, percentComplete) {
23 var percentValue = percentComplete + '%';
24 $("#progressBar").animate({
25 width: '' + percentValue + ''
30 percentText = Math.round(x * 100 / percentComplete);
31 $("#percent").text(percentText + "%");
32 if(percentText == "100") {
33 $("#outputImage").show();
38 error: function (response, status, e) {
39 alert('Oops something went.');
42 complete: function (xhr) {
43 if (xhr.responseText && xhr.responseText != "error") {
44 $("#outputImage").html(xhr.responseText);
47 $("#outputImage").show();
48 $("#outputImage").html("<div class='error'>Problem in uploading file.</div>");
49 $("#progressBar").stop();