I use $.ajax function to interact with a regular asp.net web service. My question is how do I trap errors. The web service interacts with the database and returns errors if any are encountered, but after this point, it becomes very unclear how do i trap these errors (plus others encountered during $.ajax performance).
$.ajax has callback failure with one argument msg. Do I have to do something on the web service side to populate that msg variable with the error from the database?
Could someone outline the steps I need to take in my code in order to use Jquery + ASP.net web service for a robust communication?
Thanks!
var list = [["john.doe", "corp"],["1","2","3","7"],["4","5","6"],["34","88","898"]];
var jsonText = JSON.stringify({ list: list });
$.ajax({
type: "POST",
url: "http://localhost/TemplateWebService/TemplateWebService/Service.asmx/SaveSampleTemplate",
data: jsonText,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
alert("success!");
alert(response.d);
},
failure: function(msg) {
alert("fail");
$('#pnlOutput').append('<p><font color="red">Message error ' + msg + ' </font></p>');
}
});
}