From c6e4efc268f6b2efb5009418da2350fe6fa1a6c3 Mon Sep 17 00:00:00 2001 From: qhieu45 Date: Fri, 28 Jun 2019 04:58:34 +0300 Subject: [PATCH] Update error handling instruction in $.get (#28838) Add example to handle error when calling $.get --- guide/english/jquery/jquery-ajax-get-method/index.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/guide/english/jquery/jquery-ajax-get-method/index.md b/guide/english/jquery/jquery-ajax-get-method/index.md index 7f366c400c..61dee6a542 100644 --- a/guide/english/jquery/jquery-ajax-get-method/index.md +++ b/guide/english/jquery/jquery-ajax-get-method/index.md @@ -26,13 +26,18 @@ $.get('http://example.com/resource.json', {category:'client', type:'premium'}, f $("#mypar").html(response.amount); }); ``` +However, `$.get` doesn't provide any way to handle error. -The above example can also be written as: +The above example (with error handling) can also be written as: ```javascript $.get('http://example.com/resource.json', {category:'client', type:'premium'}) .done(function(response) { alert("success"); $("#mypar").html(response.amount); + }) + .fail(function(error) { + alert("error"); + $("#mypar").html(error.statusText); }); ```