我正在尝试使用this plugin,但单击表单上的提交后我什么也没回来。

这是模态内部的形式。我正在使用 bootstrap 。

    <form id="myForm" action="#" method="post" enctype="multipart/form-data">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true" id="closeModalTimes">
            &times;
            </button>
            <h4 class="modal-title">Upload New Document</h4>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label class="control-label">Name *</label>
                        <input class="form-control" type="text" id="name" name="name" required />
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label class="control-label">Subject *</label>
                        <textarea name="subject" id="subject" class="form-control" required></textarea>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="inputFile">Document File *</label>
                        <input type="file" name="inputFile" id="inputFile" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" data-dismiss="modal" class="btn" id="closeModalButton">
            Close
            </button>
            <button type='button' id="submitFile" class='btn'>
                Send
            </button>
        </div>
    </div><!-- /.modal-content -->
    <input name="myId" type="hidden" id="myId" value="393839334034933">
    <input name="user" type="hidden" id="user" value="339">
    <input name="page" type="hidden" id="page" value="test">
    </form>

这是页面底部的jQuery
$("#inputFile").fileinput({
    overwriteInitial: false,
    maxFileSize: 4000,
    showPreview: false,
    showUpload: false,
    uploadAsync: true,
    allowedFileExtensions: ["jpg", "jpeg", "gif", "png"],
    browseClass: "btn btn-info",
    elErrorContainer: "#documentErrorBlock",
    msgSizeTooLarge: "File exceeds size",
    msgInvalidFileExtension: "Invalid extension",
    uploadURL: "upload.php",
    uploadExtraData: function() {
        return {
                id: $("#myId").val(),
                userId: $("#user").val(),
                page: $("#page").val(),
                name: $("#name").val(),
                subject: $("#subject").val()
            };
    }
});


$('#inputFile').on('filebatchuploadsuccess', function(event, data, previewId, index) {
    alert('success: '+data.response);
});

$('#inputFile').on('filebatchuploaderror', function(event, data, previewId, index) {
    alert('error: '+data.response);
});

$("#submitFile").click(function(e) {
    $('#inputFile').fileinput('upload');
});

这是PHP文件:
$output = array();
$output['message'] = 'Reached PHP';
$output['success'] = true;
echo json_encode($output);

当我单击时,什么都没有发生……没有错误消息或其他任何东西……
谢谢你的帮助!

最佳答案

未提交的原因来自您的“uploadURL”,根据文档,该URL拼写错误。
改变这个

uploadURL: "upload.php",


uploadUrl: "upload.php",

可以解决您的问题。

http://plugins.krajee.com/file-input#option-uploadurl

10-07 21:27