选择文件后立即POST [英] POST immediately after select a file

查看:100
本文介绍了选择文件后立即POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML代码

 < form action =/ script / upload_key.pymethod =POST enctype =multipart / form-data> 
密钥文件名:< input name =file_1type =file>
< input name =submittype =submit>
< / form>

这给我以下的东西。





我想知道


  1. 如何使用JavaScript来消除 Submit 按钮的需求。这意味着,一旦我选择文件,选定的文件将立即上传?

  2. 如何确保显示选中的字段文件名足够长,以便...不会显示?
  3. 立即提交,就这样做:

     < input name =file_1type =fileonchange =this。 form.submit();> 

    如果您使用的是JQuery:

      $(input [name ='file_1'])。change(function(){this.form.submit();}); 

    关于您的其他问题:

    1 )有很多方法,例如:

    http://valums.com/ajax-upload/

    http://www.webtoolkit.info/ajax-file-upload.html



    (和更多的只是谷歌:Ajax文件上传或iframe文件上传)

    2)不要担心字段的宽度。因为你不知道这条路有多长,它永远不会足够长(我认为)。另外浏览器可能会显示非常不同的内容。例如Safari或Chrome显示它与Firefox或IE非常不同。只需使用默认长度或使用您的设计看起来更好的长度即可。


    I have the following HTML code

    <form action="/script/upload_key.py" method="POST" enctype="multipart/form-data"> 
        Key filename: <input name="file_1" type="file"> 
        <input name="submit" type="submit"> 
    </form> 
    

    which gives me the following stuff.

    I was wondering

    1. How I can use JavaScript, to eliminate the need of Submit button. That's mean, once I Choose File, the selected file will be uploaded immediately?
    2. How can I make sure the field to display selected file name is long enough, so that ... will not be shown?

    解决方案

    To submit it immediately, just do this:

    <input name="file_1" type="file" onchange="this.form.submit();">
    

    If you are using JQuery:

    $("input[name='file_1']").change(function() { this.form.submit(); });
    

    About your other questions:

    1) There are many methods out there... for example:

    http://valums.com/ajax-upload/

    http://www.webtoolkit.info/ajax-file-upload.html

    (and many more. Just google for: "Ajax file upload" or "iframe file upload")

    2) Don't worry about the width of the field. As you don't know how long can it be the path, it would never be long enough (i think). Also browsers may display it very different. For example Safari or Chrome show it very different from Firefox or IE. Just use the default length or the one that looks better with your design.

    这篇关于选择文件后立即POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆