Jquery文件上传未初始化问题

时间:2015-01-08 05:50:02

标签: jquery jquery-ui file-upload jquery-file-upload

我一直在尝试使用以下测试代码上传Jquery文件:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery File Upload Example</title>
</head>
<body>
<div class="container">  
 <!-- Button to select & upload files -->
  <span class="btn btn-success fileinput-button">
<span>Select files...</span>
<!-- The file input field used as target for the file upload widget -->
<input id="fileupload" type="file" name="files[]">
</span>


 <!-- The global progress bar -->
 <p>Upload progress</p>
<div id="progress" class="progress progress-success progress-striped">
<div class="bar"></div>
</div>



  <!-- The list of files uploaded -->
  <p>Files uploaded:</p>
  <ul id="files"></ul>

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
 <script src="jquery/vendor/jquery.ui.widget.js"></script>
 <script src="jquery/jquery.iframe-transport.js"></script>
 <script src="jquery/jquery.fileupload.js"></script>
 <script>

  <!-- JavaScript used to call the fileupload widget to upload files -->

    // When the server is ready...
$(function () {
    'use strict';

    // Define the url to send the image data to
    var url = 'fileAddJquery.php';

    // Call the fileupload widget and set some parameters

    $('#fileupload').fileupload({
        url: url,
        dataType: 'json',
        done: function (e, data) {
            // Add each uploaded file name to the #files list
            $.each(data.result.files, function (index, file) {
                $('<li/>').text(file.name).appendTo('#files');
            });
        },
        progressall: function (e, data) {
            // Update the progress bar while files are being uploaded
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress .bar').css(
                'width',
                progress + '%'
            );
        }
    });
});


</script>
</div>
</body> 
</html>

html呈现正常,但是当我上传文件时,它失败并显示以下消息:

错误:在初始化之前无法调用fileupload上的方法;试图调用方法&#39;选项&#39;

即使我按照页面顶部的说明进行简单的初始化调用:https://github.com/blueimp/jQuery-File-Upload/wiki/API#initialization省略了其余的javascript代码,它也会抛出完全相同的错误。尝试过包装文件也无济于事。

如果你只是初始化并且没有执行任何方法调用,那么我在网上阅读时就不应该出现这个错误,也许我的库可能存在问题吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

无法解决JQuery文件上传遇到的问题,最后使用PLUpload http://www.plupload.com/而不是