Click on request $.ajax, how to ask him to request once, close before requesting again

Source: Internet
Author: User
Imitation is the effect of petal login, his default HTML is this

 登录

Click Login, will be in the #page with a login box,

                        

登录花瓣

使用合作网站帐号登录

新浪微博豆瓣人人网QQ

未注册过花瓣也可以直接登录哦

使用注册邮箱登录

When you click Close, the login box is deleted. And when it comes out, it pulls down, and when it's closed, it's up, and I put the code in the/include/pop-login.php.

 onclick="app.showSheet('login', {modal: true});return false;"

How he wrote that way.

$('.login').on('click',function(){    $.ajax({        async: false,        url: "/include/pop-login.php",        cache: false,        success: function(html){            $("#page").append(html);        }    });});$('#sheet_login .close').live('click',function(){    $('.sheet-overlay').remove();    $('#sheet').remove();});

Reply content:

Imitation is the effect of petal login, his default HTML is this

 登录

Click Login, will be in the #page with a login box,

                        

登录花瓣

使用合作网站帐号登录

新浪微博豆瓣人人网QQ

未注册过花瓣也可以直接登录哦

使用注册邮箱登录

When you click Close, the login box is deleted. And when it comes out, it pulls down, and when it's closed, it's up, and I put the code in the/include/pop-login.php.

 onclick="app.showSheet('login', {modal: true});return false;"

How he wrote that way.

$('.login').on('click',function(){    $.ajax({        async: false,        url: "/include/pop-login.php",        cache: false,        success: function(html){            $("#page").append(html);        }    });});$('#sheet_login .close').live('click',function(){    $('.sheet-overlay').remove();    $('#sheet').remove();});

What about the feeling?

function on_click_login(){    $.ajax({        async: false,        url: "/include/pop-login.php",        cache: false,        success: function(html){            $("#page").append(html);        },        error: function(){            $('.login').one('click',on_click_login);        }    });}$('.login').one('click',on_click_login);$('#page').on('click','#sheet_login .close',function(){    $('.sheet-overlay').remove();    $('#sheet').remove();    $('.login').one('click',on_click_login);});

PS, because do not like live so readily changed ...

Also encountered the landlord of such a problem, at that time there is no good way to solve. It was a very ugly way to get rid of the problem.
At that time, wrote a hidden variable on the page, each time before the Ajax trigger, all clear, after the Ajax execution succeeds, delay 100ms, only to give him a value, and then each time the key to determine whether the hidden variable has a value.

var popLogin = {    isLock: false,    init: function() {        if (popLogin.isLock) {            //TODO...            return false;        }        $.ajax({            url: "/include/pop-login.php",            cache: false,            success: function(html){                $("#page").append(html);            },            complete: function() {                popLogin.isLock = false;            }        });    }};$('.login').on('click', popLogin.init());

Wouldn't it be disable to drop the button at the click and then enable it at the end of Ajax ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.