我有以下对象,我需要将其转换为 ajax 帖子的数组。有谁知道如何在 javascript/jquery 中做到这一点?
[Object, Object, Object, Object]
0: Object
name: "authenticity_token"
value: "d8792991d3941352c00474e3f6b4081bd1d7e818"
1: Object
name: "_method"
value: "POST"
2: Object
name: "email"
value: "sdaasdsa"
3: Object
name: "password"
value: "asddadsadasdsa"
这是我的 jquery 帖子,我需要对象作为字段数组:
jQuery.post(formAction, fields).done(function(response) {
console.log(response);
}, "json");
谢谢 皮特
最佳答案
我认为你需要以类似的方式迭代对象:
tosend = {};
for(key in object) {
tosend[object[key].name] = object[key].value;
}
关于javascript - 将对象转换为适合 ajax post 的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17215229/