日期:2014-05-16  浏览次数:20662 次

ajaxFileUpload实现带参数提交
修改了3个地方

 [b]createUploadForm: function(id, fileElementId, data)[/b]  

    {  

        //create form     

        var formId = 'jUploadForm' + id;  

        var fileId = 'jUploadFile' + id;  

        var form = $('<form  action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');   

        var oldElement = $('#' + fileElementId);  

        var newElement = $(oldElement).clone();  

        $(oldElement).attr('id', fileId);  

        $(oldElement).before(newElement);  

        $(oldElement).appendTo(form);  

          

        //增加文本参数的支持  

        [b]if (data) {  

            for (var i in data) {  

                $('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form);  

            }  

        }  [/b]

          

        //set attributes  

        $(form).css('position', 'absolute');  

        $(form).css('top', '-1200px');  

        $(form).css('left', '-1200px');  

        $(form).appendTo('body');         

        return form;  

    },  

  

    ajaxFileUpload: function(s) {  

        // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout          

        s = jQuery.extend({}, jQuery.ajaxSettings, s);  

        var id = new Date().getTime()          

        [b]var form = jQuery.createUploadForm(id, s.fileElementId, s.data);  [/b]

        var io = jQuery.createUploadIframe(id, s.secureuri);