我有这样的输入类型文本
<input type="text" id="test" value="">
$(document).ready(function() {
$('#summernote').summernote({
height: 300, // set editor height
minHeight: null, // set minimum height of editor
maxHeight: null, // set maximum height of editor
focus: true, // set focus to editable area after initializing summernote
callbacks: {
onImageUpload: function(files) {
sendFile(files[0]);
}
}
});
function sendFile(file, editor, welEditable) {
document.getElementById("loading_upload_threads_image").style.display = "block";
data = new FormData();
data.append("file", file);//You can append as many data as you want. Check mozilla docs for this
$.ajax({
data: data,
type: "POST",
url: "threads_image_upload.PHP",
cache: false,
contentType: false,
processData: false,
success: function(url) {
$('#summernote').summernote('editor.insertimage', url);
document.getElementById("loading_upload_threads_image").style.display = "none";
}
});
}
});
我想知道如何将id =“test”的值发送到我的ajax帖子?
解决方法:
您可以使用append()方法将所需的任何数据添加到FormData对象中 – 正如您的注释事件所示.试试这个:
data = new FormData();
data.append("file", file);
data.append('test', $('#test').val());
或者,如果要发送表单中的所有数据,则可以将表单元素提供给FormData构造函数.请注意,项目将被赋予输入的名称作为键.
var data = new FormData($('form')[0]);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。