亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用甜蜜警報 2 向對象添加鍵值項時出現問題

使用甜蜜警報 2 向對象添加鍵值項時出現問題

一只甜甜圈 2022-11-11 15:01:47
我在通過 Sweet Alert 捕獲輸入值時遇到問題。我正在發送一個名為 data 的對象,然后我需要在該對象中推送一個鍵值項,但無法包含它。$("#Enviar").click(function (e) {e.preventDefault();var venta_id = $('#venta_id').val();var total = $('#total').val().replace(".", "");var descuento = $('#descuento').val();var abono = $('#abono').val();var saldo = $('#saldo').val();var comentarios = $('#comentarios').val();var fechaEntrega = $('#fechaEntrega').val();var vendedor = $('#vendedor').val();var formaPago = $('#formaPago').val();var tipoDoc = $('#tipoDoc').val();var token = '{{csrf_token()}}';var data={_token:token,venta_id:venta_id,totalAPagar:total,descuento:descuento,abono:abono,saldo:saldo,comentarios:comentarios,fechaEntrega:fechaEntrega,vendedor:vendedor,formaPago:formaPago,tipoDoc:tipoDoc};Swal.fire({  title: 'Multiple inputs',  html:'<input id="swal-input1" class="swal2-input">',  focusConfirm: false,  type: 'info',  preConfirm: () => {    return [      document.getElementById('swal-input1').value    ]  }}).then((result) => {    if (result.value) {       //const numeroDoc = result.value;       console.log(result.value);      data.push({numeroDoc:numeroDoc});            //THIS IS WHERE I CANT INCLUDE THE VALUE    }}).then(function(){$.ajax({    type: "post",    url: "{{route('ventaCorrecta')}}",    data: data,    success: function (msg) {      swal({          title: '?Venta realizada!',          text: 'La venta ha sido registrada en el sistema',          type: 'success',          allowOutsideClick: "false"        }).then(function() {            window.location.href = "{{route('home')}}";        })      }  });});});
查看完整描述

1 回答

?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

看起來您正試圖在一個不是有效函數push的對象 ( ) 上使用。data


相反,您必須numeroDoc使用點表示法將屬性添加到對象。


if (result.value) {

  data.numeroDoc = result.value;

}

有關使用對象的更多信息,請訪問MDN 頁面。


查看完整回答
反對 回復 2022-11-11
  • 1 回答
  • 0 關注
  • 81 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號