Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sarahelsaig/jquery-fetch
A promise based wrapper around jQuery that dynamically picks between get and post and implements validation and error reporting.
https://github.com/sarahelsaig/jquery-fetch
Last synced: 3 days ago
JSON representation
A promise based wrapper around jQuery that dynamically picks between get and post and implements validation and error reporting.
- Host: GitHub
- URL: https://github.com/sarahelsaig/jquery-fetch
- Owner: sarahelsaig
- License: mit
- Created: 2018-09-06T08:41:34.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-02T16:54:28.000Z (almost 5 years ago)
- Last Synced: 2023-12-03T04:21:44.319Z (12 months ago)
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jquery-fetch
A promise based wrapper around jQuery that dynamically picks between get and post and implements validation and error reporting.## Download
Find in [Releases](https://github.com/DAud-IcI/jquery-fetch/releases) or just inlcude from cdnjs:
```javascript```
## Configuration
Simply include it into your headers below jQuery.
You can specify a prefix message in the error notification by creating jQuery.fetch as an object prior to importing the library:
```html
jQuery.fetch = { fn_text: "There has been an error:", do_globals: true };
```
If `do_globals` is true it will export the utility functions into window too:
* delayelay
* animatenimate
* notifyotify
* error_fnrror_fn
* error_alertrror_alert
* error_notifyrror_notify
* error_absorbrror_absorb
* error_makeAlertWithIdrror_absorb## Usage
```javascript
jQuery.fetch('url', post_data, condition)
.then(result => do_something_with(result))
.catch(jQuery.fetch.error.notify);
```* url and post_data behave the same way as with jQuery.post, if post_data is undefined then jQuery.get will be used
* condition may be either a function or an object
- If it's a function then `condition(result)` will be called. The promise gets resolved if the function's return value is truthy, rejected otherwise.
- if it's an object then each property gets compared with the result independently.
- If it's null or undefined then no validation is done.