Display confirmation message before send ajax request

前端 未结 6 654
说谎
说谎 2021-01-02 16:28

I have written an ajax function where I want to display confirmation meeessage before submitting the form. How should I add with my condition. Below is my code.

6条回答
  •  北海茫月
    2021-01-02 17:01

    Use ajax beforeSend callback function.

    beforeSend: function () {
                        if(confirm("Are you sure?")){
                            // do something
                        } else { 
                            // stop the ajax call
                            return false;
                        }
                    },
    

    See documentation Ajax http://api.jquery.com/jquery.ajax/

提交回复
热议问题