Krajee Bootstrap File Input, catching AJAX success response

前端 未结 5 887
太阳男子
太阳男子 2021-02-08 04:22

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:38

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

提交回复
热议问题