[RESOLVED]Jquery FileUpload “fileuploadsubmit” can't send formdata to ashx

I’m trying to send some formdata programatically along with the file through the jquery fileupload plugin but it doesn’t work.

javascript code:

$(function () {
$('#fileupload').fileupload({
    filesContainer: $('#send-email-attachments'),
    uploadTemplateId: null,
    downloadTemplateId: null,
    uploadTemplate: function (o) {
        var rows = $();
        $.each(o.files, function (index, file) {
            var row = $('<tr class="template-upload fade">' +
                '<td><span class="preview file-type"></span></td>' +
                '<td><p class="name"></p>' +
                '<div class="error"></div>' +
                '</td>' +
                '<td style = "margin-right: 5px;"><p class="size"></p>' +
                '</tr>');
            row.find('.name').text(file.name);
            row.find('.size').text(o.formatFileSize(file.size));
            rows = rows.add(row);
        });
        return rows;
    },
});
$('#fileupload').bind('fileuploadsubmit', function (e, data) {
    data.formData = { ***Not Work!!!!!!!!!!!!***
        example: 'test',
    };
});

html code:

<form id="fileupload" action="TicketHandler.ashx" method="POST" enctype="multipart/form-data">
    <table id="send-email-attachments" class="attachment_list shared_attachment_list table-striped">
    </table>
    <input type="file" name="files[]" id="send-email-file" multiple>
    <div class="btn-toolbar">
        <span>
            <a  class="btn cancel_btn" href="#">Cancle</a>
        </span>
        <button type="submit" class="btn btn-primary start" id="btnTUpload">
            <i class="glyphicon glyphicon-upload"></i>
            <span>Start</span>
        </button>
    </div>
</form>

When i get data in ashx file, ‘HttpContext.Current.Request.Form’ is empty

server code

 public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        var result = string.Empty;
        var parameters = new NameValueCollection(HttpContext.Current.Request.Form);//Empty
    }

Thanks so much for your help

 

Hi zsh64,

Thanks for your post.

 As for your problem, you could refer to the following link to submit form data.

Hope it will be helpful to you.

Best Regards,

Fei Han

Leave a Reply