I am returning List<strings>
from [WebMethod]
. But when exception occurs how to return failure
message to AJAX caller?. Now I am getting build error.
JS:
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'new.aspx/GetPrevious',
data: "{'name':'" + username + "'}",
async: false,
success: function (data) {
Previous = data.d;
alert(salts);
},
error: function () {
alert("Error");
}
});
C#:
[WebMethod]
public static List<string> GetPreviousSaltsAndHashes(string name)
{
try
{
List<string> prevSalts = new List<string>();
if (reader.HasRows)
{
while (reader.Read())
{
prevSalts.Add(reader.GetString(0));
}
}
conn.Close();
return prevSalts;
}
catch (Exception ex)
{
return "failure"; //error showing here
}
}