gpt4 book ai didi

javascript - 如何通过ajax post发送值输入类型的文本?

转载 作者:可可西里 更新时间:2023-11-01 00:29:41 24 4
gpt4 key购买 nike

我有这样的输入类型文本

<input type="text" id="test" value="">

我有这样的 ajax post 函数。

$(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());

或者,如果您想发送表单中的所有数据,则可以将 form 元素提供给 FormData 构造函数。请注意,项目将以 input 的名称作为键。

var data = new FormData($('form')[0]);

关于javascript - 如何通过ajax post发送值输入类型的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40611232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com