{"id":13509009,"url":"https://github.com/fdaciuk/ajax","last_synced_at":"2025-05-16T07:04:52.528Z","repository":{"id":28285323,"uuid":"31797671","full_name":"fdaciuk/ajax","owner":"fdaciuk","description":"Ajax module in Vanilla JS","archived":false,"fork":false,"pushed_at":"2018-11-08T17:09:19.000Z","size":452,"stargazers_count":747,"open_issues_count":3,"forks_count":143,"subscribers_count":37,"default_branch":"dev","last_synced_at":"2025-05-14T03:44:22.549Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@fdaciuk/ajax","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fdaciuk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-07T02:02:59.000Z","updated_at":"2025-04-15T04:49:46.000Z","dependencies_parsed_at":"2022-08-07T13:15:39.997Z","dependency_job_id":null,"html_url":"https://github.com/fdaciuk/ajax","commit_stats":null,"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdaciuk%2Fajax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdaciuk%2Fajax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdaciuk%2Fajax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fdaciuk%2Fajax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fdaciuk","download_url":"https://codeload.github.com/fdaciuk/ajax/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485055,"owners_count":22078767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-08-01T02:01:01.716Z","updated_at":"2025-05-16T07:04:47.519Z","avatar_url":"https://github.com/fdaciuk.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Ajax\n\n\u003e Ajax module in Vanilla JS\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"ajax-logo.png\" alt=\"Ajax\" /\u003e\n\u003c/p\u003e\n\n[![Build Status][travis-image]][travis-url]\n[![Coveralls Coverage Status][coverage-image]][coverage-url]\n[![License][license-image]][license-url]\n[![CONTRIBUTING][contributing-image]][contributing-url]\n\nYou can use this module with _AMD_, _CommonJS_ or just like a method of `window` object!\n\n## Installation\n\n### Bower\n\nYou can install via bower (but you should [avoid that](https://bower.io/blog/2017/how-to-migrate-away-from-bower/)):\n\n```console\nbower install ajax\n```\n\n### Manual installation\n\nJust download `dist/ajax.min.js` file, and add `dist/ajax.min.js` on your HTML file:\n\n```html\n\u003cscript src=\"js/ajax.min.js\"\u003e\u003c/script\u003e\n```\n\n### NPM\n\n```console\nnpm i --save @fdaciuk/ajax\n```\n\n### CDN\n\nYou may use a CDN to get the latest version.\n\n**CDNJS:**\n\n```console\nhttps://cdnjs.com/libraries/fdaciuk-ajax\n```\n\n**GitHub:**\n\nOr you may just add the following line to your HTML file:\n\n```html\n\u003cscript src=\"//cdn.rawgit.com/fdaciuk/ajax/v3.0.4/dist/ajax.min.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n### AMD\n\n```js\ndefine(['ajax'], function (ajax) {\n  ajax().get(...)\n  ...\n})\n```\n\n### CommonJS\n\n```js\nvar ajax = require('@fdaciuk/ajax')\najax().post(...)\n...\n```\n\n### ES6 / ES2015 module\n\n```js\nimport ajax from '@fdaciuk/ajax'\najax().put(...)\n```\n\n### Method of `window` object\n\n```js\nwindow.ajax().get(...)\n```\n\nor just\n\n```js\najax().get(...)\n```\n\n## Signature\n\n```js\najax([options])\n```\n\n## Options\n\nOptional object with request options. See all accepted options below.\n\n**HTTP Methods**\n\nYou may pass any HTTP method as you want, using `method` property:\n\n```js\nvar request = ajax({\n  method: 'options',\n  url: '/api/users',\n  data: {\n    user: 'john'\n  }\n})\n\nrequest.then(function (response) {...})\n```\n\nFor using this kind of request, you must pass `url` property.\n\nThe property `data` is optional, but may used to pass any data via `body` on request.\n\n**headers**\n\nAn object when `key` is a header name, and `value` is a header value.\n\n```js\najax({\n  headers: {\n    'content-type': 'application/json',\n    'x-access-token': '123@abc'\n  }\n})\n```\n\nIf `content-type` is not passed, `application/x-www-form-urlencoded` will be used when you pass `data` as a _query string_.\n\nPassing `data` as `object`, `application/json` will be automatically used (_since v3.0.0_).\n\n**Note about uploads:**\n\nIf you need to upload some file, with `FormData`, use `content-type: null`.\n\n**baseUrl**\n\nYou can pass a `baseUrl` param to improve calls. Example:\n\n```js\nconst request = ajax({ baseUrl: 'http://example.com/api/v2' })\nrequest.get('/users') // get `http://example.com/api/v2/users` url\n```\n\n## Methods\n\nYou may use any of this methods, instead the above approach:\n\n### `get(url, [data])`\n\n\u003e Get data as a JSON object.\n\n```js\najax().get('/api/users')\n```\n\nYou can pass `data` on `get` method, that will be added on URL as query string:\n\n```js\najax().get('/api/users', { id: 1 })\n```\n\nIt will request on `/api/users?id=1`.\n\n### `post(url, [data])`\n\n\u003e Save a new register or update part of this one.\n\n```js\n// Without headers\najax().post('/api/users', { slug: 'john' })\n\n// With headers\nvar request = ajax({\n  headers: {\n    'x-access-token': '123@abc'\n  }\n})\n\nrequest.post('/login', { username: 'user', password: 'b4d45$' })\n```\n\n`data` might be a complex object, like:\n\n```js\najax().post('/api/new-post', {\n  slug: 'my-new-post',\n  meta: {\n    categories: ['js', 'react'],\n    tags: ['code']\n  }\n})\n```\n\n### `put(url, [data])`\n\n\u003e Update an entire register.\n\n```js\najax().put('/api/users', { slug: 'john', age: 37 })\n```\n\n### `delete(url, [data])`\n\n\u003e Delete a register.\n\n```js\najax().delete('/api/users', { id: 1 })\n```\n\n## Return methods\n\n\u003e _Disclaimer:_ these _return methods_ are not from **real Promises**, and they will just being called once.\n\u003e If you want to work with real Promises, you should make your own abstraction.\n\n### `then(response, xhrObject)`\n\n\u003e Promise that returns if the request was successful.\n\n```js\najax().get('/api/users').then(function (response, xhr) {\n  // Do something\n})\n```\n\n### `catch(responseError, xhrObject)`\n\n\u003e Promise that returns if the request has an error.\n\n```js\najax().post('/api/users', { slug: 'john' }).catch(function (response, xhr) {\n  // Do something\n})\n```\n\n### `always(response, xhrObject)`\n\n\u003e That promise always returns, independent if the status is `done` or `error`.\n\n```js\najax().post('/api/users', { slug: 'john' }).always(function (response, xhr) {\n  // Do something\n})\n```\n\n## Abort request\n\nIf a request is very slow, you can abort it using `abort()` method:\n\n```js\nconst getLazyUser = ajax().get('/api/users/lazy')\n\nconst timer = setTimeout(function () {\n  getLazyUser.abort()\n}, 3000)\n\ngetLazyUser.then(function (response) {\n  clearTimeout(timer)\n  console.log(response)\n})\n```\n\nIn the above example, if request is slowest than 3 seconds, it will be aborted.\n\n## Deprecated methods\n\nYou may see the deprecated methods [here][deprecated]\n\n## Contributing\n\nCheck [CONTRIBUTING.md][contributing-url]\n\n## Code coverage and Statistics\n\n\u003chttps://github.com/reportz/ajax\u003e\n\n## Browser compatibility\n\n| ![Chrome][chrome-logo] | ![Firefox][firefox-logo] | ![IE][ie-logo] | ![Edge][edge-logo] | ![Opera][opera-logo] | ![Safari][safari-logo] |\n| ---------------------- | ------------------------ | -------------- | ------------------ | -------------------- | ---------------------- |\n| Latest ✔               | Latest ✔                 | 9+ ✔           | Latest ✔           | Latest ✔             | 3.2+ ✔                 |\n\n## License\n\n[MIT][license-url] © Fernando Daciuk\n\n[travis-image]: https://img.shields.io/travis/fdaciuk/ajax.svg?style=flat-square\n[travis-url]: https://travis-ci.org/fdaciuk/ajax\n[coverage-image]: https://img.shields.io/coveralls/fdaciuk/ajax/master.svg?style=flat-square\n[coverage-url]: https://coveralls.io/r/fdaciuk/ajax?branch=master\n[license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\n[license-url]: https://github.com/fdaciuk/licenses/blob/master/MIT-LICENSE.md\n[contributing-image]: https://img.shields.io/badge/fdaciuk%2Fajax-CONTRIBUTE-orange.svg?style=flat-square\n[contributing-url]: CONTRIBUTING.md\n[deprecated]: deprecated.md\n[chrome-logo]: https://cdnjs.cloudflare.com/ajax/libs/browser-logos/41.2.1/chrome/chrome_48x48.png\n[firefox-logo]: https://cdnjs.cloudflare.com/ajax/libs/browser-logos/41.2.1/firefox/firefox_48x48.png\n[ie-logo]: https://cdnjs.cloudflare.com/ajax/libs/browser-logos/41.2.1/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png\n[edge-logo]: https://cdnjs.cloudflare.com/ajax/libs/browser-logos/41.2.1/edge/edge_48x48.png\n[opera-logo]: https://cdnjs.cloudflare.com/ajax/libs/browser-logos/41.2.1/opera/opera_48x48.png\n[safari-logo]: https://cdnjs.cloudflare.com/ajax/libs/browser-logos/41.2.1/safari/safari_48x48.png\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdaciuk%2Fajax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffdaciuk%2Fajax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdaciuk%2Fajax/lists"}