Krajee Bootstrap File Input, catching AJAX success response

前端 未结 5 2084
无人共我
无人共我 2021-02-08 04:21

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

5条回答
  •  抹茶落季
    2021-02-08 04:53

    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); 
    

提交回复
热议问题