在发送数据之前在ajax中使用拼接功能时出错

问题描述 投票:-2回答:1

我试图在下面的上下文中为数组使用一个拼接函数,但是页面只是在发送表单后更新。请问这里有什么机构吗?

submitHandler: function(form) {
    a = JSON.stringify($(form).serializeArray()); // a = [{"name":"1","value":"1"},{"name":"2","value":"2"},{"name":"3","value":"3"},{"name":"4","value":"4"},{"name":"5","value":"5"},{"name":"6","value":"6"}];
    a.splice(1, 4);
    var jqxhr = $.ajax({
          type: "POST",
          beforeSend: function() {
            console.log("beforeSend" + a);
          },
...
jquery arrays ajax splice
1个回答
0
投票

您可以尝试这样:

var _array= $(form).serializeArray();
_array.splice(1, 4);
submitHandler: function(form) {
    a = JSON.stringify(_array); // a = [{"name":"1","value":"1"},{"name":"2","value":"2"},{"name":"3","value":"3"},{"name":"4","value":"4"},{"name":"5","value":"5"},{"name":"6","value":"6"}];

    var jqxhr = $.ajax({
          type: "POST",
          beforeSend: function() {
            console.log("beforeSend" + a);
          },
热门问题
推荐问题
最新问题