{"id":472,"date":"2010-03-18T20:24:22","date_gmt":"2010-03-18T14:54:22","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=472"},"modified":"2010-06-09T15:34:26","modified_gmt":"2010-06-09T10:04:26","slug":"tracking-errorsexceptions-during-ajax-calls-in-a-view","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/","title":{"rendered":"Tracking Errors\/Exceptions during ajax calls in a view"},"content":{"rendered":"<p>If you want to keep track of the errors and exceptions on the view, after  making an ajax call, then this might be something of your interest : <\/p>\n<pre lang=\"javascript\">\r\njQuery().ready(function() {\r\n  jQuery.ajaxSetup({\r\n    error: function(x, e) {\r\n      if (x.status == 0) {\r\n        alert('You are offline!!\\n Please Check Your Network.');\r\n      } else if (x.status == 404) {\r\n        alert('Requested URL not found.');\r\n      } else if (x.status == 500) {\r\n        alert('Internel Server Error.');\r\n      } else if (e == 'parsererror') {\r\n        alert('Error.\\nParsing JSON Request failed.');\r\n      } else if (e == 'timeout') {\r\n        alert('Request Time out.');\r\n      }\r\n      else if (x.status == '401') {\r\n          alert('My Own Exception');\r\n        }   \r\n    }\r\n  });\r\n});<\/pre>\n<p>And in your action, you can use the following code to send a custom exception code along with a custome message:<\/p>\n<pre lang=\"groovy\">\r\nresponse.sendError(440,\"custom message\")\r\n<\/pre>\n<p>In my project I need the errors and exceptions to be shown on a page which is different from the one from which the ajax request originated. So I added the following statement in the else part :<\/p>\n<pre lang=\"groovy\">\r\nelse {\r\n         window.location = \"${createLink(controller: 'apgException', action: 'somethingWrong')}\" + \"? status=\" + x.status +\"&message=\" + x.statusText\r\n  }\r\n<\/pre>\n<p>Hope you find it useful.<br \/>\nImran Mir<br \/>\nimran@intelligrape.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to keep track of the errors and exceptions on the view, after making an ajax call, then this might be something of your interest : jQuery().ready(function() { jQuery.ajaxSetup({ error: function(x, e) { if (x.status == 0) { alert(&#8216;You are offline!!\\n Please Check Your Network.&#8217;); } else if (x.status == 404) { alert(&#8216;Requested [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5,"footnotes":""},"categories":[7],"tags":[],"class_list":["post-472","post","type-post","status-publish","format-standard","hentry","category-grails"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"If you want to keep track of the errors and exceptions on the view, after making an ajax call, then this might be something of your interest : jQuery().ready(function() { jQuery.ajaxSetup({ error: function(x, e) { if (x.status == 0) { alert(&#039;You are offline!!\\n Please Check Your Network.&#039;); } else if (x.status == 404) { alert(&#039;Requested\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Imran Mir\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Tracking Errors\/Exceptions during ajax calls in a view | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"If you want to keep track of the errors and exceptions on the view, after making an ajax call, then this might be something of your interest : jQuery().ready(function() { jQuery.ajaxSetup({ error: function(x, e) { if (x.status == 0) { alert(&#039;You are offline!!\\n Please Check Your Network.&#039;); } else if (x.status == 404) { alert(&#039;Requested\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Tracking Errors\/Exceptions during ajax calls in a view | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"If you want to keep track of the errors and exceptions on the view, after making an ajax call, then this might be something of your interest : jQuery().ready(function() { jQuery.ajaxSetup({ error: function(x, e) { if (x.status == 0) { alert(&#039;You are offline!!\\n Please Check Your Network.&#039;); } else if (x.status == 404) { alert(&#039;Requested\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/#article\",\"name\":\"Tracking Errors\\\/Exceptions during ajax calls in a view | TO THE NEW Blog\",\"headline\":\"Tracking Errors\\\/Exceptions during ajax calls in a view\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/imran\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2010-03-18T20:24:22+05:30\",\"dateModified\":\"2010-06-09T15:34:26+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/#webpage\"},\"articleSection\":\"Grails\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/#listItem\",\"name\":\"Tracking Errors\\\/Exceptions during ajax calls in a view\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/#listItem\",\"position\":3,\"name\":\"Tracking Errors\\\/Exceptions during ajax calls in a view\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/imran\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/imran\\\/\",\"name\":\"Imran Mir\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/186fa1c29a61225f60e52068be3f954d58ffa64750eac981d45154a72275b1eb?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Imran Mir\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/\",\"name\":\"Tracking Errors\\\/Exceptions during ajax calls in a view | TO THE NEW Blog\",\"description\":\"If you want to keep track of the errors and exceptions on the view, after making an ajax call, then this might be something of your interest : jQuery().ready(function() { jQuery.ajaxSetup({ error: function(x, e) { if (x.status == 0) { alert('You are offline!!\\\\n Please Check Your Network.'); } else if (x.status == 404) { alert('Requested\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/tracking-errorsexceptions-during-ajax-calls-in-a-view\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/imran\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/imran\\\/#author\"},\"datePublished\":\"2010-03-18T20:24:22+05:30\",\"dateModified\":\"2010-06-09T15:34:26+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Tracking Errors\/Exceptions during ajax calls in a view | TO THE NEW Blog","description":"If you want to keep track of the errors and exceptions on the view, after making an ajax call, then this might be something of your interest : jQuery().ready(function() { jQuery.ajaxSetup({ error: function(x, e) { if (x.status == 0) { alert('You are offline!!\\n Please Check Your Network.'); } else if (x.status == 404) { alert('Requested","canonical_url":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/#article","name":"Tracking Errors\/Exceptions during ajax calls in a view | TO THE NEW Blog","headline":"Tracking Errors\/Exceptions during ajax calls in a view","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/imran\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2010-03-18T20:24:22+05:30","dateModified":"2010-06-09T15:34:26+05:30","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/#webpage"},"articleSection":"Grails"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/www.tothenew.com\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/#listItem","name":"Tracking Errors\/Exceptions during ajax calls in a view"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/#listItem","position":3,"name":"Tracking Errors\/Exceptions during ajax calls in a view","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/imran\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/imran\/","name":"Imran Mir","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/186fa1c29a61225f60e52068be3f954d58ffa64750eac981d45154a72275b1eb?s=96&d=mm&r=g","width":96,"height":96,"caption":"Imran Mir"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/","name":"Tracking Errors\/Exceptions during ajax calls in a view | TO THE NEW Blog","description":"If you want to keep track of the errors and exceptions on the view, after making an ajax call, then this might be something of your interest : jQuery().ready(function() { jQuery.ajaxSetup({ error: function(x, e) { if (x.status == 0) { alert('You are offline!!\\n Please Check Your Network.'); } else if (x.status == 404) { alert('Requested","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/imran\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/imran\/#author"},"datePublished":"2010-03-18T20:24:22+05:30","dateModified":"2010-06-09T15:34:26+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Tracking Errors\/Exceptions during ajax calls in a view | TO THE NEW Blog","og:description":"If you want to keep track of the errors and exceptions on the view, after making an ajax call, then this might be something of your interest : jQuery().ready(function() { jQuery.ajaxSetup({ error: function(x, e) { if (x.status == 0) { alert('You are offline!!\\n Please Check Your Network.'); } else if (x.status == 404) { alert('Requested","og:url":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Tracking Errors\/Exceptions during ajax calls in a view | TO THE NEW Blog","twitter:description":"If you want to keep track of the errors and exceptions on the view, after making an ajax call, then this might be something of your interest : jQuery().ready(function() { jQuery.ajaxSetup({ error: function(x, e) { if (x.status == 0) { alert('You are offline!!\\n Please Check Your Network.'); } else if (x.status == 404) { alert('Requested","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"472","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 20:23:18","updated":"2024-02-29 09:31:27","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tTracking Errors\/Exceptions during ajax calls in a view\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Grails","link":"https:\/\/www.tothenew.com\/blog\/category\/grails\/"},{"label":"Tracking Errors\/Exceptions during ajax calls in a view","link":"https:\/\/www.tothenew.com\/blog\/tracking-errorsexceptions-during-ajax-calls-in-a-view\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=472"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/472\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}