2013-05-28 2 views
0

사용자가 양식에 전자 메일 주소를 제출하면 Fancybox를 통해 성공/실패/공유 메시지를 표시하도록 AJAX 양식을 작성하려고합니다. 현재 코드는 페이지 상단에 응답을 표시합니다.양식 제출 후 Fancybox의 성공/실패 메시지

내가 다른 답변에서 몇 가지 변화를 시도했다가 전체 양식로드 중단 삽입시로, 스택 오버플로에 hereherehere을 제공했지만 아무 소용이.

 $("#form").submit(function(e){ 

    e.preventDefault(); 

    leSubmitLoader(); 

    dataString = $("#form").serialize(); 
    var templateURL = $('#templateURL').attr('value'); 
    var blogURL = $('#blogURL').attr('value'); 

    $.ajax({ 
     type: "POST", 
     url: templateURL + "/post.php", 
     data: dataString, 
     dataType: "json", 
     success: 

     function(data) { 
    $.fancybox(
    '<p>Content of the box in HTML</p>', 
    { 
      padding:15, 
      closeBtn:true 
    } 
); 
      function leSubmit(returning){ 
            $.fancybox(

); 
       $('#form, #error, #presignup-content').hide(); 
       $('#success').fadeIn(function(){ 
        var successScroll = $('#signup-body').offset().top - 20; 
        $('html,body').animate({scrollTop:successScroll}, 300); 
       }); 

       if (returning == true) { 

        $('#returninguser, #returninguserurl').show(); 

        var refCode = data.returncode; 

        $('#returninguser span.user').text(data.email); 
        $('#returninguser span.clicks').text(data.clicks); 
        $('#returninguser span.conversions').text(data.conversions); 
        $('#returninguserurl input#returningcode').attr('value', blogURL + '/?ref=' + refCode); 

       } else { 

        $('#success-content, #newuser').show(); 

        var refCode = data.code; 

        $('#newuser input#successcode').attr('value', blogURL + '/?ref=' + refCode); 

        if(data.pass_thru_error == "blocked"){ 
         $('#pass_thru_error').fadeIn(); 
         $('#pass_thru_error').html('AWeber Sync Error: Email Blocked.'); 
        } else if (data.pass_thru_error.AWeberAPIException != undefined){ 
         err = data.pass_thru_error.AWeberAPIException; 
         $('#pass_thru_error').fadeIn(); 
         $('#pass_thru_error').html(err.type+': '+err.msg); 
        } 

       } 

       // Referral URL 
       var refUrl = blogURL + '/?ref=' + refCode; 

       // Twitter (note: refUrl might not show up in share box on localhost) 
       var tweetUrl = 'http://twitter.com/intent?url=' + encodeURIComponent(refUrl); 
       var tweetMessage = $('input#twitterMessage').attr('value'); 
       $('#tweetblock').html('<a href="https://twitter.com/share" class="twitter-share-button" data-url="'+refUrl+'" data-text="'+tweetMessage+'" data-count="none">Tweet</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>'); 

       // Facebook (note: won't work on localhost) 
       $("#fblikeblock").html('<div class="fb-like" data-ref="'+refCode+'" data-href="'+refUrl+'" data-send="false" data-width="75" data-show-faces="false" data-font="arial" data-layout="button_count"></div>'); 

       // Google + 
       function renderPlusone() { 
        gapi.plusone.render('plusoneblock', {'href':refUrl, 'size':'tall', 'annotation':'none'}); 
        } 
        renderPlusone(); 

       // Tumblr 
       var tumblr_button = document.createElement("a"); 
       tumblr_button.setAttribute("href", "http://www.tumblr.com/share/link?url=" + encodeURIComponent(refUrl) + "&name=" + encodeURIComponent(tumblr_link_name) + "&description=" + encodeURIComponent(tumblr_link_description)); 
       tumblr_button.setAttribute("title", "Share on Tumblr"); 
       tumblr_button.setAttribute("onclick", "window.open(this.href, 'tumblr', 'width=460,height=400'); return false;"); 
       tumblr_button.setAttribute("style", "display:inline-block; text-indent:-9999px; overflow:hidden; width:81px; height:20px; background:url('http://platform.tumblr.com/v1/share_1.png') top left no-repeat transparent;"); 
       tumblr_button.innerHTML = "Share on Tumblr"; 
       document.getElementById("tumblrblock").appendChild(tumblr_button); 

       // RinkedIn 
       $('#linkinblock').html('<script src="http://platform.linkedin.com/in.js" type="text/javascript"></script><script type="IN/Share" data-url="'+refUrl+'"></script>'); 

      } 

      if(data.email_check == "invalid") { 

       leSubmitLoaderStop(); 
       $('#error').html('This email address is invalid.').fadeIn(); 

      } 
      else if(data.required.length) { 

       leSubmitLoaderStop(); 
       $('.error').hide(); 
       $d = String(data.required).split(","); 
       $.each($d, function(k, v){ 
        $("#" + v + ".error").fadeIn(); 
       }); 
      } 
      else { 

       if(data.reuser == "true") { 

        leSubmit(true); 
        FB.XFBML.parse(document.getElementById('fblikeblock')); 

       } else { 

        leSubmit(false); 
        FB.XFBML.parse(document.getElementById('fblikeblock')); 

       } 
       $('body').addClass('submission-success'); 

      } 

     } 

    }); 

}); 

답변

0

내가 코드를 해결하기 위해 노력하고 있지 않다 그러나 당신은 왜 성공/실패를 처리하기 위해이 아약스 형식을 사용하지 않는 다음과 같이

나의 현재 init.js로

은?

$.ajax({ 
    type: "POST", 
    url: templateURL + "/post.php", 
    data: dataString, 
    dataType: "json" 
}).done(function() { 
    //success 
    $.fancybox("success", { 
     // options 
    }); 
}).fail(function() { 
    //error 
    $.fancybox("failure", { 
     // options 
    }); 
}).always(function() { 
    // optional after ajax is completed 
    $.fancybox("else", { 
     // options 
    }); 
});