[RESOLVED] Multiple Ajax Calls from same page-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] Multiple Ajax Calls from same page

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    241

    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.

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,011

    Re: Multiple Ajax Calls from same page

    Is this your correct code? First please use code tags to wrap your code so we can see it better.
    Also if this is your code then "respcode" is never declared. At least as a response as i am not sure that JS won't treat respcode as an object anyhow.
    Slow as hell.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    241

    Re: Multiple Ajax Calls from same page

    Quote Originally Posted by sapator View Post
    Is this your correct code? First please use code tags to wrap your code so we can see it better.
    Also if this is your code then "respcode" is never declared. At least as a response as i am not sure that JS won't treat respcode as an object anyhow.
    Thanks for your value able reply which actually helps me to solve this.
    The main issue was this that I was using OnSuccess function on both the calls I changes OnSuccess to OnSuccess1 and it works fine now.
    Thanks again.

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.