admin管理员组文章数量:1405765
I'm letting the user select files and then trying to programmatically uploading them after they click the upload button using the jquery fileupload script
The HTML looks like this:
<input name="my_image[]" id="my_file" type="file" multiple="multiple">
The jquery call looks like this:
$('#start-upload').click(function(e) {
var filesList = $('#my_file')[0].files;
//var filesList = $('#my_file').prop("files");
var url = 'photos/index.php';
$('#my_file').fileupload('send', {
files: filesList,
url: url,
dataType: 'json',
start: function(e, data) {
console.log("Upload started");
},
done: function (e, data) {
console.log("Upload plete");
}
});
});
This is the error I get:
Uncaught Error: cannot call methods on fileupload prior to initialization; attempted to call method 'send'
Any idea what I'm doing?
I'm letting the user select files and then trying to programmatically uploading them after they click the upload button using the jquery fileupload script
The HTML looks like this:
<input name="my_image[]" id="my_file" type="file" multiple="multiple">
The jquery call looks like this:
$('#start-upload').click(function(e) {
var filesList = $('#my_file')[0].files;
//var filesList = $('#my_file').prop("files");
var url = 'photos/index.php';
$('#my_file').fileupload('send', {
files: filesList,
url: url,
dataType: 'json',
start: function(e, data) {
console.log("Upload started");
},
done: function (e, data) {
console.log("Upload plete");
}
});
});
This is the error I get:
Uncaught Error: cannot call methods on fileupload prior to initialization; attempted to call method 'send'
Any idea what I'm doing?
Share Improve this question asked Jan 6, 2014 at 21:35 PaulPaul 11.8k32 gold badges92 silver badges145 bronze badges 4- 4 The error message seems pretty self explanatory to me. The very first section on the page you link to shows how to initialize the plugin. – gilly3 Commented Jan 6, 2014 at 21:37
- I must be missing the obvious... – Paul Commented Jan 6, 2014 at 21:40
-
I guess you have to initialize the fileupload with only a JS object as argument before you can call other methods on it (like
send
in this case). The link gilly3 posted shows an example of how to initialize it correctly – stex Commented Jan 6, 2014 at 21:52 -
1
I don't think what you are missing is that obvious, @Paul. I am trying to do a programmatic upload, and getting the same error. The doc does not advise that we have to initialize the plugin before calling
send
, where I assume that passing all required options in thesend
call would be enough. – ProfK Commented Dec 14, 2014 at 11:12
2 Answers
Reset to default 3It wasn't initialized. Ensure you first have something like:
$(document).ready(function(){
$('#my_file').fileupload({ url: 'your_url' ...} );
});
Cheers
To expand on Edgar's answer, this is how I set things up to programmatically submit:
//Initialize
$('#file').fileupload({
url: 'someUrl'
});
//Trigger the submit
$('#file').fileupload({
fileInput: $('#file')
});
本文标签: javascriptgetting error when trying to use jquery fileUploadStack Overflow
版权声明:本文标题:javascript - getting error when trying to use jquery fileUpload - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744897924a2631176.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论