old-fashioned-ajax

1.0.3 • Public • Published

Old Fashioned Ajax

Lightweight ajax get/post requests for old browsers.

Browser Support

Tested IE11 but it should be working with IE10+.

Installation

With npm

npm i old-fashioned-ajax -S

You can download the latest version or checkout all the releases here.

Usage

Browser

You can import this plugin into your project as follows:

<script src="path/to/old-fashioned-ajax.js"></script>

.. and you're ready to go.

Webpack

If you want to import the plugin with your webpack build you can do it by:

import "old-fashioned-ajax";

You should look at sass-loader implementation on webpack documentation for demo.

Examples

GET

var promise_ish = oldFashionedAjax('https://jsonplaceholder.typicode.com/todos/1');
  
// ...
  
promise_ish({
  success: function (res) {
    console.log(res);
  },
  error: function (res) {
    console.error(res);
  },
  always: function () {
    console.info('Always!');
  }
});

See the example on CodePen

Promise-ish?

oldFashionedAjax returns promise like function so you can collect it and then you can use it when you need it.

This is because sometimes our logic requires that to collect a promise-ish and use it later.

But if you need immediate action you can do something like this:

oldFashionedAjax(url)(options);

// or

oldFashionedAjax(url, options);

These will act immediately.

POST

var promise_ish = oldFashionedAjax('https://jsonplaceholder.typicode.com/todos/1');
  
// ...
  
promise_ish({
  type: "post",
  data: { foo: bar },
  success: function (res) {
    console.log(res);
  },
  error: function (res) {
    console.error(res);
  },
  always: function () {
    console.info('Always!');
  }
});

See the example on CodePen

Do you wanna change that long name?

oldFashionedAjax is a bit long and ugly but you can change it in your project like this:

var ajax = oldFashionedAjax;
ajax(url)(options);

Development

Clone this repo, go to the project directory and install dependencies with

npm install

and rebuild dist folder with

npm run dev
npm run prod
npm run build # alias of prod

TODO

  • [x] Add to the npm directory.

Contributors

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style.

Readme

Keywords

none

Package Sidebar

Install

npm i old-fashioned-ajax

Weekly Downloads

4

Version

1.0.3

License

Apache-2.0

Unpacked Size

27.5 kB

Total Files

15

Last publish

Collaborators

  • hayatbiralem