0

Estoy tratando de armar una funcion con sweetalert2 para enviar coordenadas por whatsapp con la api y googlemaps enviar los valores de coordenadas

CODIGO HTML

SCRIPT

Lo que no puedo lograr es mediante ajax y fetch de SweetAlert2, es el enviar los valores de las variables en el mensaje de whatsapp.

 function mensaje() {

            var reclamo = $("span[name=reclamo]").text();
            var lat = $("input[name=lat]").val();
            var lng = $("input[name=lng]").val();

           
            var aux3 = [lat, lng];




            Swal.fire({
                title: 'Ingrese numero de celular',
                input: 'text',
                inputAttributes: {
                    autocapitalize: 'off'
                },
                showCancelButton: true,
                confirmButtonText: 'Enviar',
                confirmButtonColor: '#13bb95',
                showLoaderOnConfirm: true,

                preConfirm: (aux) => {
                    return
                    fetch(`https://api.whatsapp.com/send?phone=549264${aux}&text=hola,%20Este%20reclamo%20ingreso%20recientemente%20${reclamo}%20%20https://www.google.com.ar/maps/place/${aux3}`)
                        .then(response => {
                            if (!response.ok) {
                                throw new Error(response.statusText)
                            }
                            return response.json()
                        })
                        .catch(error => {
                            Swal.showValidationMessage(
                                `Request failed: ${error}`
                            )
                        })

                },

                allowOutsideClick: () => !Swal.isLoading()

            }).then((result) => {

                if (result.isConfirmed) {
                    Swal.fire({
                        title: `${result.value.aux}'mensaje`,
                    })

                }

            })

        }

Ejemplo

Alguna Ayuda se lo agradeceria

3
  • ¿Por qué tienes un return al comienzo del preConfirm?
    – Ilsanchez
    el 22 oct. 2020 a las 14:48
  • asi esta el ejemplo de ajax request con sweetalert el 22 oct. 2020 a las 15:23
  • es la funcion por defecto de sweet alert. no se como hacer escuchar o capturar esos datos q se introducen en el input del sweet alert para despues concatenarlo a la funcion fetch para armar la url el 23 oct. 2020 a las 12:33

1 respuesta 1

0

CODIGO HTML

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>

 <button type="submit"  onclick=mensaje();                               
   class="btn btn-outline-success waves-effect waves-light ml-2"><i
   class="mdi mdi-link-variant mr-1"></i>Mensaje
 </button>

 <div class="form-group">
     <label>Nombre y Apellido</label>
     <input type="text" class="form-control" placeholder="Ingrese su nombre y apellido"
      disabled />
 </div>
 <div class="form-group">
     <label>Latitud</label>
    <input data-parsley-type="number" type="text" class="form-control" id="lat"   name="lat"                          required />
</div>
 <div class="form-group">
     <label>Longitud</label>
     <input data-parsley-type="number" type="text" class="form-control" id="lng"  name="lng"  required  />
</div>

3
  • Es una respuesta o parte de tu pregunta_?
    – user128299
    el 22 oct. 2020 a las 14:47
  • Si es parte de tu pregunta, editala, hay una opcion para que puedas editar la pregunta, despue elimina esa respuesta si no la es el 22 oct. 2020 a las 14:51
  • es el codigo html de los input y button el 22 oct. 2020 a las 15:23

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.