how to do file upload using jquery serialization

前端 未结 8 1520
感动是毒
感动是毒 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: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)
            {
                
    
            }
        });        
    
    });
    

提交回复
热议问题