<input type="file" multiple accept="image/*" class="btn btn-file" id="fileToUpload" name="file_name" multiple required/>
PURE Jquery Code:
$(document).on('change','.btn-file',function(){
var fd = new FormData();
var ins = document.getElementById('fileToUpload').files.length;
for (var x = 0; x < ins; x++) {
fd.append("fileToUpload[]", document.getElementById('fileToUpload').files[x]);
}
fd.append("user_id", $scope.user_id);
$.ajax({
url: website,
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(response) {
if (response.error_code == "SUCCESS") {
alert("uploaded successfully");
}
}
});
});
Angular JS Code with Jquery file upload:
$(document).on('change','.btn-file',function(){
var fd = new FormData();
var ins = document.getElementById('fileToUpload').files.length;
for (var x = 0; x < ins; x++) {
fd.append("fileToUpload[]", document.getElementById('fileToUpload').files[x]);
}
fd.append("user_id", $scope.user_id);
var fileConfig = {
transformRequest: angular.identity,
headers : {
//'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;',
'Content-Type': undefined,
'X-Requested-With' : 'XMLHttpRequest',
'Process-Data': false
}
}
$http.post(baseurl + '/api_v3/healthcare_provider_photo_gallery/add', fd, fileConfig).
then(function(response){
if (response.error_code == "SUCCESS") {
alert("uploaded successfully");
}
});
});
0 comments:
Post a Comment