上传两个单独的苍蝇(图片-formData)

时间:2019-07-26 20:51:47

标签: javascript jquery

我有一个表单,您可以使用formData上传图片;现在,我想添加选项以一种形式(不同标签)上传另一张图片。问题是我要针对整个表单上传第一张图片,我如何只针对第一张输入图片(元素0),然后再上传,然后再上传第二张图片(元素1)

<form class="card">
     <span class="card-image">
          <img id="promo-img-upload" class="promo-img-upload">
          <input class="img-upload" type="file" name="filename" accept="image/gif, image/jpeg, image/png">
     </span>

     <span class="card-image2">
         <img id="promo-img-reward-2" class="promo-img-reward-2">
         <input class="img-upload" type="file" name="filename" accept="image/gif, image/jpeg, image/png">
     </span>

     <span class="form-buttons">
         <button type="button" class="cancel-button" type="reset">Cancel</button>
         <button type="button" class="save-button">Save</button>
     </span>
</form>
var formData = new FormData($($(this).closest('form'))[0]);

$.ajax({
        type: 'POST',
        url: `/api/Upload-promo?promoId=${promoId}`,
        crossDomain: true,
    data: formData,
    cache: false,
    processData: false,
    contentType: false,
    beforeSubmit : function() {
    },
        success : function(responseText, statusText, xhr, $form) {
        console.log('responseText', responseText)
    }
});

0 个答案:

没有答案