我无法执行新的FormData或插入json序列
我的Json数据:
var data = {
status: "COMPLETE",
personName: $('#full_name').val(),
personPhone: $('#phone_number').cleanVal(),
personEmail: $('#e_mail').val(),
referanceFullname: $('#person_full_name').val(),
referancePhone: $('#person_phone_number').cleanVal(),
referanceEmail: $('#person_e_mail').val()
};
如何将此附加到新FormData?
答案 0 :(得分:5)
使用append
添加新数据。结帐MDN关于formData
append
var fd = new FormData();
var data = {
status: "COMPLETE",
personName: $('#full_name').val(),
personPhone: $('#phone_number').cleanVal(),
personEmail: $('#e_mail').val(),
referanceFullname: $('#person_full_name').val(),
referancePhone: $('#person_phone_number').cleanVal(),
referanceEmail: $('#person_e_mail').val()
};
$.each(data, function(key, value){
fd.append(key, value);
})
答案 1 :(得分:0)
找到一个:https://github.com/therealparmesh/object-to-formdata/
object-to-formdata
是一种便捷的JavaScript函数,可将对象转换为FormData实例。
答案 2 :(得分:-1)
你可以通过这段代码来完成。
var data = new FormData();
data.append("status", "COMPLETE");
data.append("personName", $('#full_name').val());
data.append("personPhone", $('#phone_number').cleanVal());
data.append("personEmail", $('#e_mail').val());
data.append("referanceFullname", $('#person_full_name').val());
data.append("referancePhone", $('#person_phone_number').cleanVal());
data.append("referanceEmail", $('#person_e_mail').val());
$.ajax({
type: "POST",
url: url,
processData: true,
data: data,
beforeSend: function (xhr) {
},
success: function (data) {
},
});