在函数之前执行回调

时间:2014-07-04 09:19:55

标签: javascript jquery ajax callback

  I am facing a challenge in adding the click event on a link.

    $('#submitDomainName').live('click', function(){
    fnCheckDomainNameExists();
    var myRegEx = new RegExp(/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/);
    userInputDomain = validateUserDomain($('#customDomainName').val());

    if (!userInputDomain.match(myRegEx)) {
            alert("Please enter a valid domain name");
            return;
        }
    if(confirm('Are you sure to move to a custom domain')){ 
            //alert(userCustomDomainNameUpdated);
            $.post('saveCustomDomain.php',{userExistingDomainName:userExistingDomainName,userCustomDomainName:userCustomDomainNameUpdated},function(data){
                $('#popUpContent').html('<div class="alertBoxContainer"><h2>You have Successfully Published your website on your Domain</h2><a style="color:#ffffff;" target="_blank" href="http://'+data+'">'+data+'</a><br class="clear" /></div>');
            })              
        }
     });

在上面的点击功能中我首先想要执行并检查fnCheckDomainNameExists(),然后回调继续。功能如下:

 function fnCheckDomainNameExists(){
    userInputDomain = validateUserDomain($('#customDomainName').val());     
    $.post('checkExistingDomain.php',{userInputDomain:userInputDomain},function(data){
                //alert(data);
            if(data=='false'){
                alert('Domain name already in use.Please chose a different one');
                return;
            }
        })

 }

当我点击链接而不是fnCheckDomainName时,会发生回复功能和确认框&#34; 您确定要移至自定义域会出现。我想先检查域名是否存在是新的,然后执行回调 我也试过用if(!fnCheckDomainNameExists())

0 个答案:

没有答案