mirror of
https://github.com/eldarion/eldarion-ajax.git
synced 2026-01-08 21:48:11 -05:00
Update to use jqXHR Promise methods
## 0.15.0 * Replaced `statusCode` and `complete` callbacks with Promise methods of the jqXHR object returned by `$.ajax()` (`.done()`, `.fail()`, and `.always()`) for more verbose response handling * Updated `package.json` `"jquery"` dependency to `">=1.8.3"` for consistency with `bower.json` * Bumped version of `eldarion-ajax-core.js` to 0.13.0 * Updated `README.md` to reflect changes
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
# ChangeLog
|
||||
|
||||
## 0.15.0
|
||||
|
||||
* Replaced `statusCode` and `complete` callbacks with Promise methods of the jqXHR object returned by `$.ajax()` (`.done()`, `.fail()`, and `.always()`) for more verbose response handling
|
||||
* Updated `package.json` `"jquery"` dependency to `">=1.8.3"` for consistency with `bower.json`
|
||||
* Bumped version of `eldarion-ajax-core.js` to 0.13.0
|
||||
* Updated `README.md` to reflect changes
|
||||
|
||||
## 0.14.0
|
||||
|
||||
* Reintroduced file upload support using `FormData` if it is supported by the
|
||||
|
||||
38
README.md
38
README.md
@@ -112,15 +112,11 @@ A single argument is sent with this event and is the jQuery object for the node:
|
||||
|
||||
### ```eldarion-ajax:success```
|
||||
|
||||
This is the event that is triggered once the browser receives a successful
|
||||
response (status code 200) from the server. You can handle this in order to
|
||||
provide your own processors if the ones that ship by default do not meet your
|
||||
needs.
|
||||
This event is triggered if the request succeeds. Four arguments are passed with
|
||||
this event: the jQuery object; the data returned from the server; a string
|
||||
describing the status; and the jqXHR object:
|
||||
|
||||
Two arguments are passed with this event, the jQuery object for the node, and
|
||||
the JSON data from the server:
|
||||
|
||||
$(document).on("eldarion-ajax:success", "[data-prepend-inner]", function(evt, $el, data) {
|
||||
$(document).on("eldarion-ajax:success", "[data-prepend-inner]", function(evt, $el, data, textStatus, jqXHR) {
|
||||
var $node = $($el.data("prepend-inner"));
|
||||
$node.data(data.html + $node.html());
|
||||
});
|
||||
@@ -128,19 +124,27 @@ the JSON data from the server:
|
||||
|
||||
### ```eldarion-ajax:error```
|
||||
|
||||
This event is triggered for 400, 403, 404, and 500 status codes.
|
||||
This event is triggered if the request fails. Four arguments are also passed
|
||||
with this event: the jQuery object, the jqXHR object; a string describing the
|
||||
type of error that occurred; and an optional exception object. Possible values
|
||||
for the third argument (besides null) are "timeout", "error", "abort", and
|
||||
"parsererror". When an HTTP error occurs, the fourth argument receives the
|
||||
textual portion of the HTTP status, such as "Not Found" or "Internal Server
|
||||
Error."
|
||||
|
||||
|
||||
### ```eldarion-ajax:complete```
|
||||
|
||||
This gets sent on the completion of every ajax request no matter the status
|
||||
code and in addition to the events listing above. This is triggered from the
|
||||
document rather than the element in context as the handlers processing success
|
||||
messages could replace the DOM element and therefore would prevent the event
|
||||
from reaching your listener.
|
||||
|
||||
It is passed the element (even if it no longer exists in the DOM), a ```jaXHR```
|
||||
object, and ```textStatus```.
|
||||
This event is triggered when the request finishes (after the above `success` and
|
||||
`error` events are completed). This is triggered from the document rather than
|
||||
the element in context as the handlers processing success messages could replace
|
||||
the DOM element and therefore would prevent the event from reaching your
|
||||
listener. The element is always passed as the first argument with this event
|
||||
(even if it no longer exists in the DOM). In response to a successful request,
|
||||
the arguments passed with this event are the same as those of the `success`
|
||||
event: the element, data, textStatus, and the jqXHR object. For failed requests
|
||||
the arguments are the same as those of the `error` event: the element, the jqXHR
|
||||
object, textStatus, and errorThrown.
|
||||
|
||||
|
||||
### ```eldarion-ajax:modify-data```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eldarion-ajax",
|
||||
"version": "0.13.0",
|
||||
"version": "0.15.0",
|
||||
"main": "./js/eldarion-ajax.min.js",
|
||||
"dependencies": {
|
||||
"jquery": ">=1.8.3"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* ====================================================================
|
||||
* eldarion-ajax.min.js v0.14.0
|
||||
* eldarion-ajax-core v0.12.0
|
||||
* eldarion-ajax-core v0.13.0
|
||||
* eldarion-ajax-handlers v0.1.2
|
||||
* ====================================================================
|
||||
* Copyright (c) 2015, Eldarion, Inc.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* ====================================================================
|
||||
* eldarion-ajax-core.js v0.12.0
|
||||
* eldarion-ajax-core.js v0.13.0
|
||||
* ====================================================================
|
||||
* Copyright (c) 2015, Eldarion, Inc.
|
||||
* All rights reserved.
|
||||
@@ -73,30 +73,16 @@
|
||||
cache: cache,
|
||||
processData: processData,
|
||||
contentType: contentType,
|
||||
headers: {'X-Eldarion-Ajax': true},
|
||||
statusCode: {
|
||||
200: function (responseData) {
|
||||
if (!responseData) {
|
||||
responseData = {};
|
||||
}
|
||||
$el.trigger('eldarion-ajax:success', [$el, responseData]);
|
||||
},
|
||||
500: function () {
|
||||
$el.trigger('eldarion-ajax:error', [$el, 500]);
|
||||
},
|
||||
400: function () {
|
||||
$el.trigger('eldarion-ajax:error', [$el, 400]);
|
||||
},
|
||||
403: function () {
|
||||
$el.trigger('eldarion-ajax:error', [$el, 403]);
|
||||
},
|
||||
404: function () {
|
||||
$el.trigger('eldarion-ajax:error', [$el, 404]);
|
||||
}
|
||||
},
|
||||
complete: function (jqXHR, textStatus) {
|
||||
$(document).trigger('eldarion-ajax:complete', [$el, jqXHR, textStatus]);
|
||||
headers: {'X-Eldarion-Ajax': true}
|
||||
}).done( function (responseData, textStatus, jqXHR) {
|
||||
if (!responseData) {
|
||||
responseData = {};
|
||||
}
|
||||
$el.trigger('eldarion-ajax:success', [$el, responseData, textStatus, jqXHR]);
|
||||
}).fail( function (jqXHR, textStatus, errorThrown) {
|
||||
$el.trigger('eldarion-ajax:error', [$el, jqXHR, textStatus, errorThrown]);
|
||||
}).always( function (responseData, textStatus, jqXHR) {
|
||||
$(document).trigger('eldarion-ajax:complete', [$el, responseData, textStatus, jqXHR]);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
4
js/eldarion-ajax.min.js
vendored
4
js/eldarion-ajax.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eldarion-ajax",
|
||||
"version": "0.14.0",
|
||||
"version": "0.15.0",
|
||||
"description": "a library for adding declarative ajax functionality to your website",
|
||||
"main": "js/eldarion-ajax.min.js",
|
||||
"directories": {
|
||||
@@ -20,7 +20,7 @@
|
||||
"license": "BSD",
|
||||
"readmeFilename": "README.md",
|
||||
"dependencies": {
|
||||
"jquery": "*"
|
||||
"jquery": ">=1.8.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jshint": "2.1.4"
|
||||
|
||||
Reference in New Issue
Block a user