How to upload an image through jQuery?

前端 未结 6 812
悲&欢浪女
悲&欢浪女 2020-12-09 12:11

For past few days i have been struggling to submit a form with jQuery and AJAX. The problem i\'m facing is to upload the image in the form field.

My form is somethin

6条回答
  •  执念已碎
    2020-12-09 12:51

    Try this code. using formData()

    $("form").submit(function (event) {
                
        var formData = new FormData($(this));
    
        $.ajax({
              url: url,
              type: 'POST',
              data: formData,
              async: false,
              success: function (data) {
                  //success callback
              },
              cache: false,
              contentType: false,
              processData: false
             });
    
       });
    
    

提交回复
热议问题