jquery - 使用 jquery 发送 base64 编码图像列表
问题描述
当我将 ajax 请求发送到 node.js 服务器时,包含我的图像列表的参数不会出现。(我在服务器上将请求修改为 50mb)这是我的 ajax 请求:
$.ajax({
url: '/post_vehicle',
type: "POST",
traditional: true,
data: {
images: list, // here is the problem, this var does not arrive on the server
brand: $('.post_brand :selected').text(),
model: $('.post_mark :selected').text(),
location: $('.post_location :selected').text(),
year: $('.post_year :selected').text(),
fuel_type: $('post_fuel_type :selected').text(),
}
})
我在 ajax 之前使用了 console.log 来检查列表是否有图像,它会向我显示所有图像。
这是ajax中列表的值: 列表值
解决方案
我放弃了将图像保存为 base64,而是像这样使用 FormData:
let formData = new FormData($('#sell_form')[0]);
// #sell_form is the form id where i have all the data that i need.
//Now formData variable will contain all the values from your form inputs
Ajax 请求
$.ajax({
url: '/post_vehicle',
type: 'POST',
data: formData,
dataType:'json',
processData: false,
contentType: false,
});
如果你想添加额外的数据
formData.append("Key",'Value');
推荐阅读
- android - 数据未出现在 recyclerview 中
- c# - ASP.NET。Newtonsoft.Json.JsonSerializationException:“检测到类型为“E_Store2021.Models.Product”的自引用循环
- python - Pandas 在保持价值关系的同时合并列
- c# - c#控制台linux搜索用户组
- python - 尝试使用 SQL 和 discord.py 制作一个警告命令,该命令可以显示用户被警告了多少次
- spring-boot - Nginx、spring boot hello world 和 example.com
- python - matplotlib plot x 轴未缩放到 x 轴数组
- php - 如何仅在商店页面上使用 CSS 将我的购物车隐藏在菜单中?
- uart - 修复了lora e32 ebyte之间的传输-micropython
- search - 计算二叉搜索树中项目的出现次数