Return to Snippet

Revision: 43184
at March 18, 2011 17:59 by erraja_07


Initial Code
/*** 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 ----- */

Initial URL

                                

Initial Description

                                

Initial Title
Ajax File Upload using JQuery

Initial Tags

                                

Initial Language
JavaScript