Jquery Ajax function and ASP.net web service error trapping

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('

Message error ' + msg + '

'); } }); }
The callback function is actually called "error" not "failure".

以上就是Jquery Ajax function and ASP.net web service error trapping的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准