Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mDelshad's avatar

ajax request in sweet alert

I show to user a sweet alert after sending the activation code...This sweet alert has an input that the user must enter received code and send in the ajax request, how i can do this?

swal({
                        title: 'enter confirmation code',
                        input: 'text',
                        inputPlaceholder: 'confirmation code',
                        showCancelButton: true,
                        inputClass: 'form-control',
                        inputValidator: function (value) {
                            return !value && 'You need to write something!'
                        }
                    }).then(function (result) {
                        if (result.value) {
                            swal({
                                type: 'success',
                                html: 'code, ' + result.value
                            });
                        }
                    });
0 likes
2 replies
Cronix's avatar

in your then()

if (result.value) {
     // do your ajax call
    $.ajax({
        // set your ajax settings....

       // ajax was successful, display success swal
       success: function(response) {
            swal({
                type: 'success',
                html: 'code, ' + result.value
            });
        }
    });
}

I assume you know how to set up your ajax call?

http://api.jquery.com/jquery.ajax/

1 like

Please or to participate in this conversation.