jQuery addClass example

Change class name on click in jQuery

by Nabaraj Saha

HTML

<input type="file" name="profilephoto" id="profilephoto"/>
<button id="uploadprofpic">upload</button>

JavaScript

function uploadprofilephoto() {
	var formData = new FormData();
  
	formData.append('profile_photo', $('#profilephoto')[0].files[0]);
  console.log("formdata ",formData);
	$.ajax({
       url : 'https://app.praizing.com/api/v1/rest-auth/user/',
       type : 'PUT',
       data : formData,
       headers: {"Authorization": "Token 23b79d4e6c10062c157a71f76843d87e31b9b6f5"},
       processData: false,  // tell jQuery not to process the data
       contentType: false,  // tell jQuery not to set contentType
       success : function(data) {
           console.log(data);
           alert(data);
       }
	});
}

$("#uploadprofpic").click(function(){
	uploadprofilephoto();
});