如何使用jquery cropper发送表单数据?

时间:2018-03-21 15:57:36

标签: jquery ajax cropper

我正在使用cropper jquery库,现在我正在向服务器发送POST请求,其中包含表单数据和裁剪图像

 display_img.cropper('getCroppedCanvas').toBlob(function (blob) {
    var formData = new FormData();

    formData.append('croppedImage', blob);

    var data = {
        name: name,
        description: description,
        croppedImage: formData,
        nsfw: nsfw,
        cover: cover,
        pictures: pictures,
        videos: videos,
        mods: mods,
    };

    $.ajax({
        type: 'POST',
        url: '/kategorija',
        data: data,
        processData: false,
        contentType: false,
        success: function (data) {
            console.log(data);
        },
        error: function (err) {
            console.log(err);
        }
    });
});

但是这不起作用,因为在服务器上我得到空的请求。当我从数据中移除croppedImage时,以及在{j} processDatacontentType中移除formData时,它会正常工作,我会收到所有其他数据。那么如何将Sub ExtractComments() Dim ExComment As Comment Dim i As Integer Dim ws As Worksheet Dim CS As Worksheet Set CS = ActiveSheet If ActiveSheet.Comments.Count = 0 Then Exit Sub For Each ws In Worksheets If ws.Name = "Comments" Then i = 1 Next ws If i = 0 Then Set ws = Worksheets.Add(After:=ActiveSheet) ws.Name = "Comments" Else: Set ws = Worksheets("Comments") End If For Each ExComment In CS.Comments ws.Range("A1").Value = "Comment In" ws.Range("B1").Value = "Comment By" ws.Range("C1").Value = "Comment" With ws.Range("A1:C1") .Font.Bold = True .Interior.Color = RGB(189, 215, 238) .Columns.ColumnWidth = 20 End With If ws.Range("A2") = "" Then ws.Range("A2").Value = ExComment.Parent.Address ws.Range("B2").Value = Left(ExComment.Text, InStr(1, ExComment.Text, ":") - 1) ws.Range("C2").Value = Right(ExComment.Text, Len(ExComment.Text) - InStr(1, ExComment.Text, ":")) Else ws.Range("A1").End(xlDown).Offset(1, 0) = ExComment.Parent.Address ws.Range("B1").End(xlDown).Offset(1, 0) = Left(ExComment.Text, InStr(1, ExComment.Text, ":") - 1) ws.Range("C1").End(xlDown).Offset(1, 0) = Right(ExComment.Text, Len(ExComment.Text) - InStr(1, ExComment.Text, ":")) End If Next ExComment End Sub 与其他数据一起发送?

1 个答案:

答案 0 :(得分:1)

您必须将所有数据添加到FromData对象(通过追加),然后将FormData对象作为ajax请求中的数据参数传递。