# jquery-ajax-native

> jQuery Plugin that adds XHR2 responseType support

Latest version **2.0.0** (published 2019-10-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install jquery-ajax-native
pnpm add jquery-ajax-native
yarn add jquery-ajax-native
bun add jquery-ajax-native
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-10-11 |
| First published | 2015-07-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 34 |
| Author | Tarik Zakaria Benmerar |
| Maintainers | tarikbenmerar |
| Keywords | jquery, ajax, XHR2, responseType |

## Links

- npm: https://www.npmjs.com/package/jquery-ajax-native
- Repository: https://github.com/acigna/jquery-ajax-native
- Homepage: https://github.com/acigna/jquery-ajax-native#readme
- Issues: https://github.com/acigna/jquery-ajax-native/issues
- npm.io page: https://npm.io/package/jquery-ajax-native

## Dependencies (1)

- [jquery](https://npm.io/package/jquery.md) ~3

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2019-10-11
- 1.0.2 — 2018-02-01
- 1.0.0 — 2015-07-05

## README

# Description
XHR2 provides a response attribute, that contains a converted response to a native object, depending on the responseType ("arraybuffer", "blob", "document", "json"). 

See:

https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-response-attribute
http://www.html5rocks.com/en/tutorials/file/xhr2/?redirect_from_locale=fr

Using this mechanism provides better performances compared to a javascript way of conversion. For example, converting an ArrayBuffer, leads to a heavy loop (See: http://updates.html5rocks.com/2012/06/How-to-convert-ArrayBuffer-to-and-from-String).

This jQuery Plugin adds XHR2 responseType support, that is currently lacking support in jQuery.ajax and probably remains
in the future (See the last comments on this [pull request](https://github.com/jquery/jquery/pull/1525)).

Please, take a look at XHR2 current support [here](http://caniuse.com/#feat=xhr2) for more precision on the support status.

# Usage
The plugin provides two means to get a native ajax response as follows.

## Using jQuery.ajax
The Plugin provides the native data type for the ajax method that you should use to have a native response. You should also precise the responseType on xhrFields to precise the expected native data type. This usage method allows more customization but
it is more verbose.
``` javascript
$.ajax({
    dataType: 'native',
    url: dataUrl,
    xhrFields: {
      responseType: 'arraybuffer'
    },
    success: successCallback
});
```

## Using jQuery.getNative wrapper method
The getNative method is a shortened version of the previous method. It allows to specify a success callback only, but returns a promise, and so permets to add the error case.
``` javascript
//With success callback
$.getNative( dataUrl, successCallback );
//Using the returned promise (success and error callbacks respectively)
$.getNative( dataUrl ).then( successCallback, errorCallback );
```

---
_Source: https://npm.io/package/jquery-ajax-native · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
