Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unjq-ajax

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unjq-ajax

AJAX library abstracted from jQuery offers the same APIs.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

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)

Keywords

FAQs

Package last updated on 24 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc