ua

unjq-ajax

An AJAX library abstracted from jQuery offers the same APIs as jQuery AJAX without other redundancy

Showing:

Popularity

Downloads/wk

1

GitHub Stars

0

Maintenance

Last Commit

6yrs ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

6.1KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

UnJQ-Ajax

An AJAX library abstracted from jQuery offers the same APIs as jQuery AJAX without other redundancy.

Installation

npm install unjq-ajax

Features

Ajax methods in jQuery style

such as: .ajax, .get, .post, .getJSON, .getScript

Linkable event-handlers

such as: .then(func), .done(func), .fail(func), .always(func)

Global events are NOT supported

such as: ajaxStart, ajaxSend, ajaxSuccess, ajaxError, ajaxComplete, ajaxStop

Practical methods

serialize ( form )

Encode a set of form elements as a string for submission.

  • @form: FORM HTMLElement

serializeArray ( form )

Encode a set of form elements as an array of names and values.

  • @form: FORM HTMLElement

Unchanged methods in jQuery style

such as isFunction, isWindow, isPlainObject, extend, param

upload ( fileElements , url [, data ][, success] [, dataType ] )

Upload file(s) with one or several file input elements.

  • @fileElements: single of array of File Input HTMLElements.
  • @url: A string containing the URL to which the request is sent.
  • @data: A plain object or string that is sent to the server with the request.
  • @success: A callback function that is executed if the request succeeds. Required if dataType is provided, but you can use null as a placeholder.
  • @dataType: The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).

Examples

import modules

    import UnJQ, {serialize, upload} from 'unjq-ajax'

GET

    UnJQ.get('/json'
        , { memo: 'Hello World' }
        , (resp) => {
            //TODO
        }, 'json')
        .done(() => {
            //TODO
        })
        .fail(() => {
            //TODO
        })
        .always(() => {
            //TODO
        })

getJSON

    UnJQ.getJSON('/json'
        , (resp) => {
            //TODO
        })
        .fail(() => {
            //TODO
        })

getScript

    UnJQ.getScript( "test.js"
        , ( data, textStatus, jqxhr ) => {
            console.log( data ); // Data returned
            console.log( textStatus ); // Success
            console.log( jqxhr.status ); // 200
            console.log( "Load was performed." );
        })

POST & Form Serialization

    UnJQ.post('/post'
        , serialize( document.getElementById('form1') )
        , (resp) => {
            //TODO
        }, 'json')

Simple File Upload

    let file = document.getElementById('theFile')
    upload(file, '/post'
        , serialize( document.getElementById('form1') )
        , (resp) => {
            //TODO
        })

Run Demo

Run the server

    node examples/server.js

DEMO Links

  • http://localhost:3000

##License

MIT (http://www.opensource.org/licenses/mit-license.php)

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial