Lightweight ajax get/post requests for old browsers.
Tested IE11 but it should be working with IE10+.
With npm
npm i old-fashioned-ajax -S
You can download the latest version or checkout all the releases here.
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.
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.
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
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.
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
oldFashionedAjax is a bit long and ugly but you can change it in your project like this:
var ajax = oldFashionedAjax;
ajax(url)(options);
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
- [x] Add to the npm directory.
In lieu of a formal style guide, take care to maintain the existing coding style.