0
我一直在嘗試使用jQuery文件上傳,使用下面的測試代碼: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渲染罰款,但是當我把它上傳失敗,出現以下消息的文件:
錯誤:不能調用在初始化之前文件上傳的方法;試圖調用方法'選項'
即使我做了一個簡單的初始化調用,如頁面頂部所述:https://github.com/blueimp/jQuery-File-Upload/wiki/API#initialization忽略了其餘的javascript代碼它引發完全相同的錯誤。已經試過在文檔中打包也無濟於事。
從我在網絡上閱讀,如果你只是簡單的初始化和不執行調用,那麼應該不會出現這種錯誤的任何方法,或許可能會有一個問題與庫即時通訊使用?
在此先感謝。
對於初學者來說,嘗試添加一個'
' – pmahomme添加形式,仍然給出相同的錯誤消息。 – robbyc73