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

Error when use splice function in ajax before send data

我尝试在下面的上下文中对数组使用拼接函数,但页面在发送表单后才更新。这里有任何人如何解决它吗?

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);
          },
...

你可以这样试试:

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);
          },