jQuery serialize方法不适用于输入类型文件

时间:2011-07-08 00:39:57

标签: jquery

我找到了这个插件:http://jquery.malsup.com,它运行得很好,但我想在没有插件的情况下这样做。有人能帮助我吗?

2 个答案:

答案 0 :(得分:1)

您无法序列化文件上传。 Javascript无权访问将要上传的文件数据。

上传(不使用applet /组件)的唯一方法是发布文件输入所在的表单。

答案 1 :(得分:0)

是的,你可以@Guffa;我做到了。

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://{url}/js/ajaxfileupload.js"></script>
<script src="http://{url}/js/jquery.form.js"></script> 

<script>
(function() {

var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');

$('#txtrform').ajaxForm({
    beforeSend: function() {
        status.empty();
        var percentVal = '0%';
        bar.width(percentVal)
        percent.html(percentVal);
    },
    uploadProgress: function(event, position, total, percentComplete) {
        var percentVal = percentComplete + '%';
        bar.width(percentVal)
        percent.html(percentVal);
    },
    success: function() {
        var percentVal = '100%';
        bar.width(percentVal)
        percent.html(percentVal);
    },
    complete: function(xhr) {
        status.html(xhr.responseText);
    }
}); 

})();       
</script>
<script>
$(document).ready(function(){

    $("#txtrform").submit(function(){

        $.post($(this).attr('action'), $(this).serialize(), function(data) {
            $("#col3").load("/include/txtrpbox/feed.php");
            $('input#txtrinput').val('');
        });

        return false;
    });

});
</script>
相关问题