how to do file upload using jquery serialization

前端 未结 8 1440
感动是毒
感动是毒 2020-11-22 16:28

So I have a form and I\'m submitting the form through ajax using jquery serialization function

        serialized = $(Forms).serialize();

        $.ajax({
         


        
相关标签:
8条回答
  • 2020-11-22 17:21

    HTML5 introduces FormData class that can be used to file upload with ajax.

    FormData support starts from following desktop browsers versions. IE 10+, Firefox 4.0+, Chrome 7+, Safari 5+, Opera 12+

    FormData - Mozilla.org

    0 讨论(0)
  • 2020-11-22 17:23

    Use FormData object.It works for any type of form

    $(document).on("submit", "form", function(event)
    {
        event.preventDefault();
        $.ajax({
            url: $(this).attr("action"),
            type: $(this).attr("method"),
            dataType: "JSON",
            data: new FormData(this),
            processData: false,
            contentType: false,
            success: function (data, status)
            {
    
            },
            error: function (xhr, desc, err)
            {
                
    
            }
        });        
    
    });
    
    0 讨论(0)
提交回复
热议问题