Been answered quite a few times look up JavaScript for a redirect
window.location.href = "whatever location";
Before I was making:
$this->validate($request,[
'import_file' => 'required',
]);
$db_header_obj = new Voter();
$db_header = $db_header_obj->getTableColumns();
$path = $request->file('import_file')->getRealPath();
$csv = Reader::createFromPath($path, 'r');
$csv->setHeaderOffset(0); //set the CSV header offset
$csv_header = $csv->getHeader();
$sample_data = $csv->fetchOne();
$sample_data = array_values($sample_data);
$extension = $request->file('import_file')->getClientOriginalExtension();
$filename = uniqid().'_'.time().'_'.date('Ymd').'.'.$extension;
Storage::disk('local')->putFileAs('/files/voter/', $request->file('import_file'), $filename);
$arr = [
'action' => 'storeCSV',
'table' => $this->table,
];
$this->storeActivity($arr);
return view('admin.voter.import_fields', compact( 'csv_header', 'db_header','sample_data','filename'));
<form action="{{url('admin/voter/sub/storecsv')}}" class="form-horizontal file-upload" id="file_upload" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<input required="" type="file" name="import_file" id="import_file" />
<br>
<br>
<button class="btn btn-success btn-sm" id="upload_csv" disabled="true" type="submit">Import CSV or Excel File</button>
</form>
$(document).ready(function(){
$('form').submit(function(event){
event.preventDefault();
var formData = new FormData($(this)[0]);
$.ajax({
headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') },
url: "{{url('admin/voter/sub/storecsv')}}",
data: formData,
type: 'post',
cache: false,
xhr: function() {
var xhr = new window.XMLHttpRequest();
$("#csv_uploading").modal('show');
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
$('.uploadProgressBar').attr('aria-valuenow',percentComplete).css('width',percentComplete + '%').text(percentComplete + '%');
if (percentComplete === 100) {
$("#csv_uploading").modal('hide');
}
}
}, false);
return xhr;
},
processData: false,
contentType: false,
success:function(data){
if(data.success === true){
window.href
}
}
});
});
});
Required flow:
Note: import_fields is just the partial.
I don't know if this is what you are looking, but I could show you how you can tackle this problem.
return response()->json(array('success' => true, 'filename'=>$filename));
success:function(data){
if(data.success === true){
$("#modal_id").modal('hide');
$('<input />').attr('type', 'hidden') .attr('name', "filename") .attr('value', data.filename).appendTo('#hidden_form_id');
$('#hidden_form_id').submit();
}
}
Please or to participate in this conversation.