为了账号安全,请及时绑定邮箱和手机立即绑定

使用甜蜜警报 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 关注
  • 57 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信