I’m calling the Page Method and it’s returning all of the HTML in this page and not the value of 1 or 0.
I don’t know why this is. Can someone point me in the right direction ?
JavaScript:
$.ajax({
async: false,
type: "POST",
contentType: "application/json; charset=utf-8",
data: '{}',
url: "main.aspx/IsInfoComplete",
success: function(data, textStatus, jqXHR) {
console.log(textStatus);
console.log(data.d);
// act on return value:
if(data==0) {
// todo -
} else if (data==1) {
// todo -
}
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus);
}
});
Server:
[System.Web.Services.WebMethod()]
public int IsInfoComplete()
{
int returnValue = 0;
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetIsUserInfoComplete";
cmd.Parameters.AddWithValue("@UserName", userName);
conn.Open();
try
{
returnValue = (int)cmd.ExecuteScalar();
}
catch (Exception) { /* todo - */ }
}
return returnValue;
}
One thing you might try is to write your
successfunction like this,And change your server side method to return a
bool. This would probably get you the desired results. I had to do this in something I wrote and it worked just fine. Little silly that you have to check for “False” but it worked.Note: Case matters when looking for the word “False”