在提交之前附加更多数据以形成?

时间:2013-04-25 03:36:51

标签: jquery forms blob form-submit multipartform-data

我无法弄清楚为什么这不起作用?

var $formElement = $("#upload-form");
var formData = new FormData($formElement);
formData.append("file", blob_output, "timelapse.webm");
formData.append('token', token);

$formElement.submit();

我想在提交timelapse.webm时附加文件token以及$("#upload-form")数据。它似乎没有用。

检查员显示这是空的:

This is the request payload.

相关资料: https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/FormData/Using_FormData_Objects#Retrieving_a_FormData_object_from_an.C2.A0HTML.C2.A0form

1 个答案:

答案 0 :(得分:0)

您需要发送FormData,而不是提交HTML表单。例如:

$.ajax({
    url: submitUrl,
    data: formData,
    processData: false,
    contentType: false,
    type: 'POST',
    success: function(data) {
        ...
    }
});