Update error handling instruction in $.get (#28838)
Add example to handle error when calling $.get
This commit is contained in:
@ -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);
|
||||
});
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user