Home > Software design >  sweetalert2 ajax send otp code and get json response php
sweetalert2 ajax send otp code and get json response php

Time:11-02

I want to send the otp code in ajax form with enter image description here

Please help me because I did not find a useful source that works. Thank you.

CodePudding user response:

I think you can get your values ​​using the name of each value in json result.value['name']. Pay attention to my code please

Swal.fire({
            title: 'Submit your Github username',
            input: 'text',
            inputAttributes: {
                autocapitalize: 'off'
            },
            showCancelButton: true,
            inputValue: resolve,
            confirmButtonText: 'Look up',
            showLoaderOnConfirm: true,
            preConfirm: function () {
                return $.ajax({
                    type: 'POST',
                    //   dataType: "JSON",
                    url: aw_ajax.aw_ajax_url,
                    data: {
                        'action': 'aw_confirm_user_ajax_in_account',
                        'securityconfirn': aw_ajax.aw_nonce_referer,
                        'numberconfirm': resolve,
                    }

                }).then(response => {
                  //  aw_ajax_confirm_optCode(response);
                  var obj = JSON.parse(response);
                  // console.log(obj['number']);
                  // console.log(response);
                    return obj;
                }).catch(error => {
                    //   console.log(error); // Nice to view which properties 'error' has
                })

            },
            allowOutsideClick: () => !Swal.isLoading()
        }).then((result) => {
            if (1) {
             console.log(result);
             console.log( result.value);
              Swal.fire({
                  title :result.value['number'],
                  text :result.value['message'],
              });
            }
        });
  • Related