How to show uploaded by appending in Jquery or returning from AJAX?
I am uploading a profile pic. I am using an image with user icon. But, when I upload it with AJAX, I am returning 1, which means it is successfully uploaded. Then, I want to either append the image in place of user icon or return the value from Controller to show the image there.
For Html
<div class="col-md-12 pr-0">
@if(!empty($profile->pics))
<img src="{!! asset('pmc_assets/teacher') !!}/" class="img-fluid rounded-circle normal centered mb-3 pic-uploader" width="200">
@else
<img src="{!! asset('pmc_assets/img/add-profile.png') !!}" class="img-fluid rounded-circle normal centered mb-3 pic-uploader" width="200">
@endif
<input type="file" name="file_up" id="FileUpload1" class="d-none">
<p class="text-dark-grey text-center f-ur f-18">Profile Picture</p>
</div>
For Controller
if (Input::get('ajax') == 2) {
$file = Input::file('image');
$destination = base_path('public/pmc_assets/teacher/');
$file_name = upload_file($file, $destination);
TeacherRequests::where(['user_id' => Auth::id(), 'active' => 1, 'approved' => 1]) - > update(['pics' => $file_name]);
return ["status" => 1, "message" => "Details Changed"];
}
For Jquery
$.ajax({
type: "POST",
data: form,
cache: false,
contentType: false,
processData: false,
success: function(data) {
if (data.status == 1) {
$('.alert_text').append('<div class="col-md-12 alert alert-success alert-dismissible"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> Pic Updated Succesfully. </div>')
} else {
$('.alert_text').append('<div class="col-md-12 alert alert-danger alert-dismissible"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> Unknown Error </div>')
}
}
});
How to do it?
from Laravel Questions and Answers https://laravelquestions.com/laravel/how-to-show-uploaded-by-appending-in-jquery-or-returning-from-ajax/
via Lzo Media
No comments:
Post a Comment