微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用 jquery 发送 base64 编码图像列表

当我向 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');

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。