I am using the Krajee Bootstrap File Input plugin to load via an AJAX call.
Here is the link to the Krajee AJAX plugin : Krajee AJAX plugin
I use the following JS and PHP codes (codeigniter):
JS:
<script> $("#file-upload").fileinput({ 'allowedFileExtensions' : ['csv'], 'maxFileSize': 5120, 'maxFileCount': 1, 'uploadUrl': 'dashboard/uploader', 'elErrorContainer': '#errorBlock', 'uploadAsync': true, 'msgInvalidFileExtension': 'Invalid extension for file "{name}". Only "{extensions}" files are supported.', 'uploadExtraData': {csrf_token_name: $("input[name=csrf_token_name]").val()} }); </script>
PHP:
public function uploader(){ $config['upload_path'] = './csv_uploads/'; $config['allowed_types'] = 'csv'; $config['max_size'] = '5120'; $this->upload->initialize($config); if (!$this->upload->do_upload("file-upload")){ $data['error'] = 'The following error occured : '.$this->upload->display_errors().'Click on "Remove" and try again!'; echo json_encode($data); } else { echo json_encode("success"); } }
Right now I get a response from PHP, whatever it is - a mistake or success, as in JSON, I looked at the plugin documentation and still can not find how to intercept the AJAX answer and act in accordance with this answer, as we do in jQuery. with ajax success function:
success: function (response) {
How can i do this?
javascript jquery ajax php twitter-bootstrap
oussama kamal
source share