jQuery AJAX 'multipart/form-data' Not Sending Data?

后端 未结 1 2018
梦毁少年i
梦毁少年i 2020-11-29 05:38

I\'m at a loss for why I can\'t get jQuery to pass upload data seeing as the AJAX object appears to be configured correctly, and the correct Content-Type/MIME-Type headers a

相关标签:
1条回答
  • 2020-11-29 05:54

    You have to pass the FormData object as the data parameter

    var request = new FormData();                   
    $.each(context.prototype.fileData, function(i, obj) { request.append(i, obj.value.files[0]); });    
    request.append('action', 'upload');
    request.append('id', response.obj.id);
    $.ajax({
    
        type        : 'POST',
        url     : context.controller,
        data        : request,
        processData : false,
        contentType : false,                        
        success     : function(r) {
            console.log(r);
            //if (errors != null) { } else context.close();
    
        },
    
        error       : function(r) { alert('jQuery Error'); }
    
    });
    
    0 讨论(0)
提交回复
热议问题