将var附加到FormData [英] Append var to FormData
问题描述
我正在使用CKEditor作为所构建的内部电子邮件系统的WYSIWYG编辑器,这需要我从textarea输入中获取数据,如下所示:
I am using CKEditor as a WYSIWYG editor for an internal email system that I'm building, which requires me to get the data from from the textarea input like this:
var message = CKEDITOR.instances.messageArea.getData();
我还允许用户发送附件,并通过HTML5 FormData将文件发送到服务器.
I am also allowing users to send attachments and I am sending the files to the server via the HTML5 FormData.
//create form variable
var form = $('#sendIndividualEmail')[0];
var formData = new FormData(form);
我尝试将message变量追加到formData,但是formData似乎只允许将表单字段追加.
I have tried to append the the message variable to the formData, but it seems that formData only allows form fields to be appended.
如果不是表单字段,是否有其他方法可以将var附加到FormData?如果没有,是否还有另一种方法可以使用formData将消息变量获取到服务器?
Is there alternative way to append a var to FormData if it isn't a form field? If not, is there another way to get the message variable to the server with the formData?
ajax代码:
request = $.ajax({
url: baseURL+'/sendIndividualMessage',
type: "post",
data: formData,
mimeType: "multipart/form-data",
dataType: json,
contentType: false, //required for formData
cache: false,
processData: false, //require for formData
});
推荐答案
您可以像这样将数据附加到FormData上:
You can append data to a FormData like that :
formData.append('message', message);
它不必是一个表单字段. 要调试FormData,您必须发布数据.
It doesn't need to be a form field. To debug FormData, you have to post the data.
在这里看看: FormData.append("key","value" ;)无法正常工作
这篇关于将var附加到FormData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!