带有序列化和数据数组的 jQuery post()

标签 jquery jquery-post

我在 mvc 3 中发布期间无法获得收藏值(value)。 它返回 null。

$.post("/Work/Post", { vm: $('#myForm').serializeArray(), 'collection': ['a', 'b', 'c'] });

//Or


var data = $('#myForm').serializeArray();
data.push({ name: 'collection', value: ['a', 'b', 'c'] });
$.post("/Work/Post", data);

//Or

var data = $('#myForm').serializeArray();
data.push({ name: 'collection[]', value: ['a', 'b', 'c'] });
$.post("/Work/Post", data);

最佳答案

我在传递数组时遇到了类似的问题。

不要使用 $.post,而是使用 $.ajax 并设置 traditional 选项 = true .. .

$.ajax({
    type: "POST",
    url: "Work/",
    traditional: true,
    data: { collection: ['a','b','c'] }
});

traditional: true 选项很重要

关于带有序列化和数据数组的 jQuery post(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11868051/

相关文章:

javascript - 为什么这些数据表函数是 'undefined' ?

javascript - jQuery appendTo 在 $.post 下不起作用

ajax - jQuery Ajax 未执行

javascript - JQuery 单击时未打开对话框

javascript - 如何处理单击和选项卡中的焦点?

javascript - 这个错误有什么建议吗?未捕获的类型错误 : $. ajax 不是函数

php - 如何创建像ebay所有类别页面上的动态链接列表?

jQuery - 检查 URL 中的 POST

post - 可以在 Chrome 扩展中使用 jQuery POST 吗?