Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Displaying A String Returned From A Web Service In An AJAX Call

$
0
0

Hi all,

My web method in my web service successfully retrieved the total row count from a database. If the return value is zero the variable "is_unique" is set to "true" else if the return value is 1 or more, it is set to "false". Then the variable "is_unique" is returned. The following are my code snippets.

//--------------- Web Service Code Snippet

[WebMethod]
public string function GetTotal(string firstname, string lastname)
{

if(firstname.length==0){return"Please enter first name";};

 if(lastname.length==0){return"Please enter last name";}; 

string is_unique = "false";

//---- ADO.NET Code goes here
//---- More ADO.Net code
//---- More ADO.NET code
//---- More ADO.NET code
//---- More ADO.NET code

con.Open();
cmd.ExecuteNonQuery();

int count = Convert.ToInt32(outputParam.Value);
if (count == 0) { is_unique = "true"; }
else if(count>=1) { is_unique = "false"; }
con.Close();
return is_unique;
}
//--------------AJAX function on the frontend 

function IsUnique() {
var jdata = {firstname: "Test", lastname: "Test"};$.ajax({
                url: "http://localhost:21577/MyService.asmx/GetTotal",              
                data:jdata,
                method: "Post",                
                dataType: "xml",
                success: function (data) {                 
                    alert(data.value);
                }
            });
}

The problem I am having is that when I try to retrieve data from the web service in the AJAX call on the frontend using "data.value", I get "Undefined". Please help me resolve this problem.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>