weixin_33736649 2015-12-10 14:32 采纳率: 0%
浏览 235


I'm facing problem with my popup ajax contact form because it have only one close event...

My AJAX contact form have two buttons SEND and CANCEL. When i use SEND button the Sweet alert confirmation show correct message. But when i close the window by button CANCEL or click outside the window or use X button on the corner the same confirmation message is showing and this is problem

My js code

            'hideOnContentClick': false,
            'afterClose' : function(){
                    title: 'Thanks dude!',
                    text: 'You are awesome!',
                    type: 'success',
                    showConfirmButton: false,
                    timer: '5000'

My ajax call

                    url: "ajax_form.php",
                    post: "POST",
                    data: $('#contact').serialize(),
                    dataType: "json"
                });     $.fancybox.close();

So when someone hit SEND button $.fancybox.close(); will close the window and Sweet Alert give nice info with great success. How to add or disable Sweet Alert confirmation when someone use CANCEL button or use other close action?

  • 写回答

1条回答 默认 最新

  • weixin_33725272 2015-12-10 15:00

    Thinking in another way to close it, you can try adding a common class or something to the CANCEL, X button and the parent element outside the fancybox. Then with jQuery (or JS), you can define a function that closes it and avoid the ajax call. For example, add a common class class="preventAjax". Then with jQuery:

    $('.preventAjax').click(function() {$.fancybox.close();});

    Other than that, you can close it with Css, but I recommend closing it with the commands that the API provides.

    Hope that helps!




    • ¥15 PMM 9010/30P
    • ¥15 pom文件依赖管理,未找到依赖
    • ¥15 现在后端返回给我一堆下载地址,都是一个视频切片后的,如何在uniapp安卓环境下将这些分片的视频下周并且合并成原始视频并下载到本地。
    • ¥15 Unity导出2D项目运行时图片变成马赛克
    • ¥15 关于communitytoolkit.mvvm的生成器得到的代码看起来没有被使用的问题
    • ¥15 matlab中此类型的变量不支持使用点进行索引
    • ¥15 咨询第六届工业互联网数据创新大赛原始数据
    • ¥15 Pycharm无法自动补全,识别第三方库函数接收的参数!
    • ¥15 STM32U575 pwm和DMA输出的波形少一段
    • ¥30 android百度地图SDK海量点显示标题