Results 1 to 3 of 3

Thread: [RESOLVED] Multiple Ajax Calls from same page

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    243

    Resolved [RESOLVED] Multiple Ajax Calls from same page

    Hi, on my page I've to check if the UserName is available and sponsor code is correct. For that I'm using ajax call for both.

    Code:
    Sponsor User Name &nbsp; <span id = "mesg"></span><asp:TextBox ID="txtSpUserName" runat="server" CssClass="DropText" onblur ="ShowAvailability()"></asp:TextBox>
    
    Login Name <span id="Login"></span><asp:TextBox ID="txtLoginName" runat="server" CssClass="DropText" onblur ="ShowLoginName()"></asp:TextBox>
    
    Script in head tag
    
    <script type = "text/javascript">
              function ShowAvailability() {              
                  $.ajax({
                      type: "POST",
                      url: "NewJoin.aspx/CheckUserName",
                      data: '{userName: "' + $("#<%=txtSpUserName.ClientID%>")[0].value + '" }',
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      success: OnSuccess,
                      failure: function (response) {
                          alert(response);
                      }
                  });
              }
              function OnSuccess(response) {
                  var mesg = $("#mesg")[0];
                  mesg.style.color = "#06536e";
                  mesg.innerHTML = response.d;
                  switch (response.d) {                                
                      case "true":
                          mesg.style.color = "green";
                          mesg.innerHTML = "Available";
                          break;
                      case "Sponsor Not found":
                          mesg.style.color = "red";
                          mesg.innerHTML = "Sponsor Not found";
                          break;
                      case "error":
                          mesg.style.color = "red";
                          mesg.innerHTML = "Error occured";
                          break;
                  }
              }
              function OnChange(txt) {
                  $("#mesg")[0].innerHTML = "";
              }
        </script>
    
    Works fine for single ajax call but if I write another call then it updates the second span only
    
    <script type = "text/javascript">
                                        function ShowLoginName() {
                                            $.ajax({
                                                type: "POST",
                                                url: "NewJoin.aspx/CheckUsers",
                                                data: '{userName: "' + $("#<%=txtLoginName.ClientID%>")[0].value + '" }',
                                                contentType: "application/json; charset=utf-8",
                                                dataType: "json",
                                                success: OnSuccess,
                                                failure: function (respcode) {
                                                    alert(respcode);
                                                }
                                            });
                                        }
                                        function OnSuccess(respcode) {
                                            var logs = $("#Login")[0];
                                            logs.style.color = "#06536e";
                                            logs.innerHTML = respcode.d;
                                            switch (respcode.d) {
                                                case "true":
                                                    logs.style.color = "green";
                                                    logs.innerHTML = "Available";
                                                    break;
                                                case "Sponsor Not found":
                                                    logs.style.color = "red";
                                                    logs.innerHTML = "Sponsor Not found";
                                                    break;
                                                case "error":
                                                    logs.style.color = "red";
                                                    logs.innerHTML = "Error occured";
                                                    break;
                                            }
                                        }
                                        function OnChange(txt) {
                                            $("#Login")[0].innerHTML = "";
                                        }
                                    </script>
    Can anyone helps on this? Why they are not giving separate results?
    Last edited by ravininave; Sep 1st, 2014 at 01:47 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width