使用 jquery 发送 base64 编码图像列表

Send a list of base64 encoded images using jquery

当我向 node.js 服务器发送 ajax 请求时,包含我的图像列表的参数没有出现。 (我在服务器上将请求修改为 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 中列表的值: List value

我放弃了将图像保存为 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');