上传未知错误

时间:2012-01-31 18:39:12

标签: javascript jquery uploadify

我似乎无法使用Uploadify(2.1.4)工作,在Google Chrome Inspector中,控制台在初始化期间没有显示任何错误,但是,点击“选择文件”按钮不会发生任何事情,按下上传按钮会导致:< / p>

Uncaught TypeError: Object #<HTMLObjectElement> has no method 'startFileUpload'

我不知道在哪里看,奇怪的是它只在调用任何按钮或函数时显示错误,但是.uploadify();工作正常。

我正在使用:   - JQuery 1.7.1   - Twitter Bootstrap(在这种情况下是twipsy&amp; modal javascript文件)

这是代码:

<script type="text/javascript">
$(function(){
    $("#uploadPopup").modal({
        backdrop: "static",
        keyboard: false
    });

    var uploadBox = '<div id="status-message">Select some files to upload:</div>\
                    <div id="fileQueue"></div>\
                    <input id="fileUploadSelector" type="file" name="Filedata" />';
    var uploadInProgress = false;

    $("#uploadphoto").click(function(){
        $("#uploadPopup h3").html("Video Uploader");
        $("#uploadPopup .modal-body").html(uploadBox);

        $('#fileUploadSelector').uploadify({
            'uploader': 'static/flash/uploadify/uploadify.swf',
            'script': 'www.example.com/script.php',
            'cancelImg': 'static/images/uploadify/cancel.png',
            'multi': true,
            'auto': false,
            'fileExt': '*.jpg;*.gif;*.png;*.bmp',
            'fileDesc': 'Image Files (.JPG, .GIF, .PNG, .BMP)',
            'queueID': 'fileQueue',
            'queueSizeLimit': 100,
            'simUploadLimit': 2,
            'removeCompleted': true,
            'buttonText': 'Select Files',
            'onSelectOnce': function (event, data) {
                $('#status-message').text(data.filesSelected + ' files have been added to the queue.');
            },
            'onAllComplete': function (event, data) {
                $('#status-message').text(data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.');
                uploadInProgress = false;
                $("#uploadMedia").button('reset');
            },
            'onClearQueue': function (event, data) {
                $('#status-message').text('Upload Cancelled');
                uploadInProgress = false;
                $("#uploadMedia").button('reset');
            }
        });

        $("#uploadPopup").modal({
            backdrop: "static",
            keyboard: false
        });
    });

    $("#uploadMedia").live('click', function(){
        $("#fileUploadSelector").uploadifyUpload();
        uploadInProgress = true;
    });

    $("#cancelUpload").live('click', function(){
        var answer = confirm("Are you sure you want to cancel the upload?");
            if(answer) {
                $("#fileUploadSelector").uploadifyClearQueue();
                $('#uploadPopup').modal('hide');
                return true;
            } else {
                return false;
            }
    });
});
</script>

HTML部分:

<div class="btn success" id="uploadphoto">Upload Photo</div>

<div id="uploadPopup" class="modal hide">
    <div class="modal-header">
        <h3>Photo viewer</h3>
    </div>
    <div class="modal-body">
    </div>
    <div class="modal-footer">
        <a href="#" class="btn primary" id="uploadMedia" data-toggle="Uploading..">Upload</a>
        <a href="#" class="btn secondary" id="cancelUpload">Cancel</a>
    </div>
</div>

说明:   - 用户按下#uploadphoto按钮并显示模态(在此步骤中,uploadify也会初始化)   - 模态包含一个按钮(#uploadMedia),当按下该按钮时,开始上传。   - 按取消按钮(#cancelUpload)取消上传并关闭模态

请注意,这仍然是一些原型编码,仍然必须进行清理。

感谢您提前提供任何帮助。

1 个答案:

答案 0 :(得分:1)

Uploadify fails to open file browser?

这家伙有同样的问题,看起来这是跨子域调用脚本的问题。 很高兴我能帮忙!