/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/*** AJAX UPLOAD PROFILE IMAGE - STARTS ***/ function profileImgUpload(form_obj) { var fileToUpload = $("input#profile_image").val(); // first hide any error messages $('.error').hide(); if (fileToUpload == "") { $("label#profile_image_error").show(); $("label#profile_image_error").html('This field is Required'); $("input#profile_image").focus(); return false; } else if(validateImageFile(fileToUpload) == false) { $("label#profile_image_error").show(); $("label#profile_image_error").html('Invalid file type'); $("input#profile_image").focus(); return false; } else { $("#fade_f").hide(); $("#popup_label").hide(); $("#profile_image_div").ajaxStart(function(){ $(this).html('<img src="images/default/community/ajax-loader.gif" />'); }) .ajaxComplete(function(){ //$(this).html(''); }); $.ajaxFileUpload ( { url:'ajax_profile_image_upload.php', secureuri:false, fileElementId:'profile_image', dataType: 'json', success: function (data, status) { if(typeof(data.error) != 'undefined') { if(data.error != '') { alert(data.error); }else { var output = data.msg.split('#@#'); $("#profile_image_div").html(output[0]); $("#hidden_image").val(output[1]); } } }, error: function (data, status, e) { alert(e); } } ) return false; } } /* ----- ENDS ----- */