Javascript 使用sweet alert 2向对象添加键值项时出现问题

Javascript 使用sweet alert 2向对象添加键值项时出现问题,javascript,ajax,object,sweetalert,Javascript,Ajax,Object,Sweetalert,我无法通过Sweet Alert捕获输入值。我正在发送一个名为data的对象,然后我需要在该对象中插入一个键值项,但无法包含它 $("#Enviar").click(function (e) { e.preventDefault(); var venta_id = $('#venta_id').val(); var total = $('#total').val().replace(".", ""); var descuento = $

我无法通过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')}}";
        })
      }
  });
});
$(“#Enviar”)。单击(函数(e){
e、 预防默认值();
var venta_id=$('#venta_id').val();
var total=$('#total').val().replace(“.”,”);
var descumento=$('#descumento').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数据={u标记:标记,venta_id:venta_id,totalAPagar:total,Descento:Descento,abono:abono,saldo:saldo,comentarios:comentarios,fechaEntrega:fechaEntrega,vendedor:vendedor,formaPago:formaPago,tipoDoc:tipoDoc};
喷火({
标题:“多输入”,
html:“”,
focusConfirm:false,
键入:“info”,
预确认:()=>{
返回[
document.getElementById('swal-input1')。值
]
}
})。然后((结果)=>{
if(result.value){
//常量numeroDoc=结果值;
console.log(result.value);
data.push({numeroDoc:numeroDoc});//这是我不能包含值的地方
}
}).然后(函数(){
$.ajax({
类型:“post”,
url:“{route('ventaCorrecta')}}”,
数据:数据,
成功:功能(msg){
游泳({
标题:“‘万塔实现’”,
文字:“系统中的注册登记”,
键入:“成功”,
allowOutsideClick:“false”
}).然后(函数(){
window.location.href=“{{route('home')}}”;
})
}
});
});

}))

看起来您试图在一个无效函数的对象(
数据)上使用
推送

相反,您必须使用点符号将
numeroDoc
属性添加到对象中

if (result.value) {
  data.numeroDoc = result.value;
}

有关使用对象的详细信息,请访问。

从何处获得
numeroDoc
值?