|
-
Aug 31st, 2014, 02:49 PM
#1
Thread Starter
Addicted Member
[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 <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.
-
Aug 31st, 2014, 06:03 PM
#2
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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Sep 1st, 2014, 01:47 AM
#3
Thread Starter
Addicted Member
Re: Multiple Ajax Calls from same page
 Originally Posted by sapator
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|