dongweicha6077 2016-01-20 05:11
浏览 63

Jquery fileupload库没有调用onchange函数

I am using Jquery fileupload library(blue emp, https://blueimp.net) for uploading the file.
I have table consisting fileupload control in each row.

<table id="recordTable" class="table table-bordered table-striped">
                    <thead>
                        <tr>                    
                            <th>Question Number</th>
                            <th>Question Text</th>
                            <th>Supported Document</th>
                            <th>File Upload Status</th>                                 
                            <th>Delete</th>
                        </tr>                       
                    </thead>

                    <tbody>
                            <tr>
                                <td class="ques_id">17</td>
                                <td class="ques_text">asddsf</td>
                                <td class="ques_file"><input type="file" name="supportingDocument" accept="application/pdf" id="uploadSupportingDoc"></td>
                                <td class="fileuploadSuccess"></td>                                 
                                <td><a href="#" id="deleteButton" class="btn btn-primary">delete</a></td>
                            </tr>

                            <tr>
                                <td class="ques_id">18</td>
                                <td class="ques_text">dfgdfg</td>
                                <td class="ques_file"><input type="file" name="supportingDocument" accept="application/pdf" id="uploadSupportingDoc"></td>
                                <td class="fileuploadSuccess"></td>                                 
                                <td><a href="#" id="deleteButton" class="btn btn-primary">delete</a></td>
                            </tr>

                    </tbody>
                </table>

Onchange event for the fileupload, what I am doing here is sending data of first column i.e questionId(it's unique id column)

$('#uploadSupportingDoc').on("change", function(){ 
   console.log("on change called!");
   var questionId = $(this).parent().siblings(":first").text(); 

   console.log("fileUpload called with Id =>"+questionId);
   uploadFile(questionId); 
});

asdsad

function uploadFile(questionId) {


 $('#uploadSupportingDoc').fileupload({
    url: 'uploadSupportingDoc.html',
    formData: {questionId: questionId },
    acceptFileTypes: /(\.|\/)(jpe?g)$/i,
    maxFileSize: 100,
    dropZone: null,
    pasteZone: null,
    fileInput: $(this),
    dataType: 'json',
    add: function(e, data){
             $(this).closest('tr').children('td.fileuploadSuccess').html('<img src="./img/ajax-loader.gif" alt="Uploading..." />');
           data.submit();
    },
    done: function (e, data){
        var response = data.result.files[0];
        console.log("done");
        if(!response.isRequestValid)
        {
            window.location = "requestDenied.html";
        }
        else
        {

            if(response.status)
            {

                $(this).closest('tr').children('td.fileuploadSuccess').html("<span class=\"glyphicon glyphicon-ok\" aria-hidden=\"true\"></span>")

            }
            else
            {
                $(this).parent().siblings().find(".fileuploadSuccess").html("<span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span>")

            }
        }
    },
    fail: function(e, data){
        console.log("failed");

        console.log(data.jqXHR.responseText);
        console.log(data.jqXHR+"\m");
    },
    always: function (e, data){
        console.log("in always");
    }
 });

}

what is happening here is only on first attemp $('#uploadSupportingDoc').on("change", function(){ }) is getting called,
after that every subsequent change event is directly calling $('#uploadSupportingDoc').fileupload() function. why is it happening?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请分析一下这个电路设计的优点🙏
    • ¥15 求视频摘要youtube和ovp数据集
    • ¥15 怎么改成输入一个要删除的数后现实剩余的数再输入一个删除的数再现实剩余的数用yes表示继续no结束程序
    • ¥15 在启动roslaunch时出现如下问题
    • ¥15 汇编语言实现加减法计算器的功能
    • ¥20 关于多单片机模块化的一些问题
    • ¥30 seata使用出现报错,其他服务找不到seata
    • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
    • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
    • ¥15 Google speech command 数据集获取