Skip to content

Commit 9e8fcac

Browse files
citygentAurelioDeRosa
authored andcommitted
Updated Ajax page to remove deprecated methods
Fixes jquerygh-665 Closes jquerygh-669
1 parent 45df607 commit 9e8fcac

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

page/ajax/jquery-ajax-methods.md

+28-29
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,26 @@ $.ajax({
3030
3131
// The type of data we expect back
3232
dataType : "json",
33+
})
34+
// Code to run if the request succeeds (is done);
35+
// The response is passed to the function
36+
.done(function( json ) {
37+
$( "<h1>" ).text( json.title ).appendTo( "body" );
38+
$( "<div class=\"content\">").html( json.html ).appendTo( "body" );
39+
})
40+
// Code to run if the request fails; the raw request and
41+
// status codes are passed to the function
42+
.fail(function( xhr, status, errorThrown ) {
43+
alert( "Sorry, there was a problem!" );
44+
console.log( "Error: " + errorThrown );
45+
console.log( "Status: " + status );
46+
console.dir( xhr );
47+
})
48+
// Code to run regardless of success or failure;
49+
.always(function( xhr, status ) {
50+
alert( "The request is complete!" );
51+
});
3352
34-
// Code to run if the request succeeds;
35-
// the response is passed to the function
36-
success: function( json ) {
37-
$( "<h1>" ).text( json.title ).appendTo( "body" );
38-
$( "<div class=\"content\">").html( json.html ).appendTo( "body" );
39-
},
40-
41-
// Code to run if the request fails; the raw request and
42-
// status codes are passed to the function
43-
error: function( xhr, status, errorThrown ) {
44-
alert( "Sorry, there was a problem!" );
45-
console.log( "Error: " + errorThrown );
46-
console.log( "Status: " + status );
47-
console.dir( xhr );
48-
},
49-
50-
// Code to run regardless of success or failure
51-
complete: function( xhr, status ) {
52-
alert( "The request is complete!" );
53-
}
54-
});
5553
```
5654

5755
**Note:** Regarding the `dataType` setting, if the server sends back data that is in a different format than you specify, your code may fail, and the reason will not always be clear, because the HTTP response code will not show an error. When working with Ajax requests, make sure your server is sending back the data type you're asking for, and verify that the `Content-type` header is accurate for the data type. For example, for JSON data, the `Content-type` header should be `application/json`.
@@ -68,7 +66,15 @@ Set to `false` if the request should be sent synchronously. Defaults to `true`.
6866

6967
Whether to use a cached response if available. Defaults to `true` for all `dataType`s except "script" and "jsonp". When set to `false`, the URL will simply have a cachebusting parameter appended to it.
7068

71-
#### complete
69+
#### done
70+
71+
A callback function to run if the request succeeds. The function receives the response data (converted to a JavaScript object if the `dataType` was JSON), as well as the text status of the request and the raw request object.
72+
73+
#### fail
74+
75+
A callback function to run if the request results in an error. The function receives the raw request object and the text status of the request.
76+
77+
#### always
7278

7379
A callback function to run when the request is complete, regardless of success or failure. The function receives the raw request object and the text status of the request.
7480

@@ -84,17 +90,10 @@ The data to be sent to the server. This can either be an object or a query strin
8490

8591
The type of data you expect back from the server. By default, jQuery will look at the MIME type of the response if no `dataType` is specified.
8692

87-
#### error
88-
89-
A callback function to run if the request results in an error. The function receives the raw request object and the text status of the request.
90-
9193
#### jsonp
9294

9395
The callback name to send in a query string when making a JSONP request. Defaults to "callback".
9496

95-
#### success
96-
97-
A callback function to run if the request succeeds. The function receives the response data (converted to a JavaScript object if the `dataType` was JSON), as well as the text status of the request and the raw request object.
9897

9998
#### timeout
10099

0 commit comments

Comments
 (0)