Uploading both data and files in one form using Ajax?

后端 未结 10 874
无人共我
无人共我 2020-11-21 05:48

I\'m using jQuery and Ajax for my forms to submit data and files but I\'m not sure how to send both data and files in one form?

I currently do almost the same with b

10条回答
  •  面向向阳花
    2020-11-21 06:27

    Or shorter:

    $("form#data").submit(function() {
        var formData = new FormData(this);
        $.post($(this).attr("action"), formData, function() {
            // success    
        });
        return false;
    });
    

提交回复
热议问题