admin管理员组文章数量:1420073
I am using the AjaxFileUpload script and it works well, however i was trying to get it to require the pressing of a button. Right now it fires directly after you find your image to upload on the file browser. I cannot tell why and I think it is how the plugin is written, but maybe you can take a look at the logic:
This method works: The file is uploaded right after it is submitted.
<form method="post" action="" enctype="multipart/form-data">
<label>File Input: <input type="file" name="file" id="demo1" /></label>
<div id="uploads">
</div>
</form>
<script type="text/javascript">
$(document).ready(function() {
$("#demo1").AjaxFileUpload({
});
</script>
This method does not work. Clicking the Submit button will do nothing. However, the second time a file is browsed to (file button is clicked for a second time) it will operate in the same manner as the first method.
<form method="post" action="" enctype="multipart/form-data">
<label>File Input: <input type="file" name="file" id="demo1" /></label>
<div id="uploads">
</div>
</form>
<input class = "Submit" name="Submit" type="button" value="Submit" />
<script type="text/javascript">
$(document).ready(function() {
$(".Submit").click(function(){
$("#demo1").AjaxFileUpload({
});
});
});
</script>
I think there is a fundamental programming issue here I am missing. If you are interested in the (short) code of this plugin here is the link: .ajaxfileupload.js
I am using the AjaxFileUpload script and it works well, however i was trying to get it to require the pressing of a button. Right now it fires directly after you find your image to upload on the file browser. I cannot tell why and I think it is how the plugin is written, but maybe you can take a look at the logic:
This method works: The file is uploaded right after it is submitted.
<form method="post" action="" enctype="multipart/form-data">
<label>File Input: <input type="file" name="file" id="demo1" /></label>
<div id="uploads">
</div>
</form>
<script type="text/javascript">
$(document).ready(function() {
$("#demo1").AjaxFileUpload({
});
</script>
This method does not work. Clicking the Submit button will do nothing. However, the second time a file is browsed to (file button is clicked for a second time) it will operate in the same manner as the first method.
<form method="post" action="" enctype="multipart/form-data">
<label>File Input: <input type="file" name="file" id="demo1" /></label>
<div id="uploads">
</div>
</form>
<input class = "Submit" name="Submit" type="button" value="Submit" />
<script type="text/javascript">
$(document).ready(function() {
$(".Submit").click(function(){
$("#demo1").AjaxFileUpload({
});
});
});
</script>
I think there is a fundamental programming issue here I am missing. If you are interested in the (short) code of this plugin here is the link: https://github./davgothic/AjaxFileUpload/blob/master/jquery.ajaxfileupload.js
Share Improve this question edited Apr 16, 2014 at 5:26 Madhu 2,5513 gold badges20 silver badges34 bronze badges asked Apr 16, 2014 at 4:47 user3479138user3479138 573 silver badges7 bronze badges 2-
use
https://github./LPology/Simple-Ajax-Uploader
with callback functionsonChange( filename, extension, uploadBtn )
oronSubmit( filename, extension, uploadBtn )
– waki Commented Apr 16, 2014 at 5:25 - have't find submit button in first html code !!! – Manwal Commented Apr 16, 2014 at 5:32
2 Answers
Reset to default 2You have probably got a fix for this at this point. But for the sake of others that could be ing in here to find an answer for the same problem, here is how it's done.
There is a parameter in the ajaxfileupload method call, called submit_button. If you set that, the file will NOT be automatically uploaded when you select it. The method will actually wait for you to press the specified button for the upload to happen.
Based on the example you provided, this would do it:
Add an ID to the submit button (haven't tested with the JQuery class specifier):
<input class = "Submit" name="Submit" id="Submit" type="button" value="Submit" />
Then add the submit_button parameter:
$("#demo1").AjaxFileUpload({
// other parameters omitted like in example provided
'submit_button': $('#Submit')
});
Use this:
<script type="text/javascript">
$(document).ready(function() {
$("#demo1").AjaxFileUpload({
});
$(".Submit").click(function(){
$("#myform").submit();
});
});
</script>
myform is the id of form.
HTML:
<form method="post" action="" enctype="multipart/form-data" id="myform">
<label>File Input: <input type="file" name="file" id="demo1" /></label>
<div id="uploads">
</div>
</form>
<input class = "Submit" name="Submit" type="button" value="Submit" />
本文标签: javascriptUsing the AjaxFileUpload functionStack Overflow
版权声明:本文标题:javascript - Using the AjaxFileUpload function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745331579a2653837.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论