2009-10-31 5 views
1

내 응용 프로그램에서 사용자가 사용자 이름을 먼저 입력하는 양식이 있습니다. 이제 그 사용자 이름을 사용할 수 있는지 여부를 확인해야한다. 그렇지 않으면 반환 유형으로 true 또는 false를 반환하는 "username"메서드를 사용해야한다. 여기 나는 ajax와 함께 jQuery를 사용하여이 개념을 구현하고있다. 일단 사용자가이 이름을 입력하면 두 번째 텍스트 상자에이 코드를 입력하면이 코드가 실행되어 팝업으로 결과가 나타납니다. [moda popup] 사용자 이름의 메서드 "username"에서 반환 값이 true이면 반환 값이 false이면 메시지를 표시해야합니다. "표시 할 필요가 없습니다"asp.net의 JQuery에서 서버 측 메서드 호출

지금 내 코드는 다음과 유사합니다.

<head> 
    <title>Calling an ASP.NET Page Method with jQuery</title> 
    <script type="text/javascript" src="jquery-1.2.6.min.js"></script> 
<script type="text/javascript"> 

     $(document).ready(function() {  
      $.ajax({  
       type: "POST",  
       url: "Default.aspx/Username",  
       contentType: "application/json; charset=utf-8",  
       data: "{}",  
       dataType: "json",  
       success: OnSuccess,  
       error: OnFailure  
      });  
    }); 

     function OnSuccess(result) 
     { 
     // so here i need to check whethere true or false 
     // based on that i need to show modal pop up 
      alert("Success!");  
     } 

     function OnFailure (result)  
     { 
      alert("The call to the page method failed.");  
     }  
    </script>  
</head> 

여기에 대한 해결책은 당신에게

답변

2
<asp:TextBox id="txtUserName" runat="server"/> 
<div id="divPrompt" style="display:none">User Name alredy in use</div> 
<input id="otherText"...../> 

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#<%= txtUserName.ClientID%>").blur(function(){ 
     $.ajax({  
       type: "POST",  
       url: "Default.aspx/Username",  
       contentType: "application/json; charset=utf-8",  
       data: "{}",  
       dataType: "json",  
       success: function (msg){ 
        if(msg.hasOwnProperty("d")){ 
        OnSuccess(msg.d); 
        } else{ 
        OnSuccess(msg); 
        } 
       }, 
       error: OnFailure 
      });  
    }); 
}); 

    function OnSuccess(result) 
    { 
    if(result.UserNameInUser) 
     $("div#divPrompt").show(); 
    else 
     $("div#divPrompt").hide(); 
    } 

    function OnFailure (result)  
    { 
     alert("The call to the page method failed.");  
    }  
</script> 
감사 좋은 것
관련 문제