I\'m using Krajee the Bootstrap File Input plugin to perform an upload via AJAX call.
Here is the link to the Krajee plugin AJAX section: Krajee plugin AJAX
The
You can check out a demo here live demo
Remember to set uploadAsync false if you want the success event fire
Example code:
JS
$("#input-id").fileinput({
showRemove:false,
showPreview: false,
uploadUrl: "../xxxx/xxxx/XXXXXX.php", // server upload action
uploadAsync: false,
uploadExtraData: function() {
return {
bdInteli: xxxx
};
}
});
// CATCH RESPONSE
$('#input-id').on('filebatchuploaderror', function(event, data, previewId, index) {
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
});
$('#input-id').on('filebatchuploadsuccess', function(event, data, previewId, index) {
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
alert (extra.bdInteli + " " + response.uploaded);
});
PHP
$nombre = $_FILES["ficheroExcel"]["name"];
$bdInteli = $_POST['bdInteli'];
if (move_uploaded_file($_FILES["ficheroExcel"]["tmp_name"], $nombre) ){
$output = array('uploaded' => 'OK' );
} else {
$output = array('uploaded' => 'ERROR' );
}
echo json_encode($output);