{"id":19772966,"url":"https://github.com/Kira-NT/SimpleAjax","last_synced_at":"2025-04-30T18:31:20.791Z","repository":{"id":57359740,"uuid":"202864712","full_name":"Kir-Antipov/SimpleAjax","owner":"Kir-Antipov","description":"Vanilla JavaScript library, which designed to make simple ajax-requests","archived":false,"fork":false,"pushed_at":"2020-04-02T08:21:18.000Z","size":21,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T06:21:45.055Z","etag":null,"topics":["ajax","ajax-library","vanilla-javascript","vanilla-js"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kir-Antipov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-17T10:04:52.000Z","updated_at":"2023-02-25T17:40:55.000Z","dependencies_parsed_at":"2022-09-06T21:41:06.051Z","dependency_job_id":null,"html_url":"https://github.com/Kir-Antipov/SimpleAjax","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kir-Antipov%2FSimpleAjax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kir-Antipov%2FSimpleAjax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kir-Antipov%2FSimpleAjax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kir-Antipov%2FSimpleAjax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kir-Antipov","download_url":"https://codeload.github.com/Kir-Antipov/SimpleAjax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224219648,"owners_count":17275477,"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":["ajax","ajax-library","vanilla-javascript","vanilla-js"],"created_at":"2024-11-12T05:08:16.000Z","updated_at":"2025-04-30T18:31:15.507Z","avatar_url":"https://github.com/Kir-Antipov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleAjax.js\n-------------\n\n`SimpleAjax.js` - vanilla JavaScript library, which designed to make simple ajax-requests\n\n## Usage\n\n```js\n// GET request to specified URL without parameters\najax(url);\n\n// or\najax(url, options);\n\n// HTMLFormElement (\u003cform\u003e) could be a single argument\n// if it has an `action` attribute, which will be used as `url`.\n// Its `method` attribute will be used as `method`. \najax(form);\n\n// or\najax(form, options);\n\n// or just\najax(options);\n```\n\n## Options\n\n - `url` \u003csub\u003e\u003ci\u003e(string)\u003c/i\u003e\u003c/sub\u003e - requested resource's url\n - `method` (or `type`) \u003csub\u003e\u003ci\u003e(string)\u003c/i\u003e\u003c/sub\u003e - request method (`GET`, `POST`, `HEAD` etc)\n - `data` (or `content`) \u003csub\u003e\u003ci\u003e(object | HTMLFormElement | string)\u003c/i\u003e\u003c/sub\u003e - object, form (or its selector)\n - `success` \u003csub\u003e\u003ci\u003e(function(AjaxResult))\u003c/i\u003e\u003c/sub\u003e - callback on successful request completion\n - `error` \u003csub\u003e\u003ci\u003e(function(AjaxResult))\u003c/i\u003e\u003c/sub\u003e - callback on request failure\n - `statusCode` \u003csub\u003e\u003ci\u003e(object)\u003c/i\u003e\u003c/sub\u003e - an object of numeric HTTP codes and functions to be called when the response has the corresponding code\n - `headers` \u003csub\u003e\u003ci\u003e(object)\u003c/i\u003e\u003c/sub\u003e - dictionary of request headers\n - `beforeSend` \u003csub\u003e\u003ci\u003e(function(XMLHttpRequest))\u003c/i\u003e\u003c/sub\u003e - function for modifying a request before sending it\n - `beforeReturn` \u003csub\u003e\u003ci\u003e(function(AjaxResult, XMLHttpRequest))\u003c/i\u003e\u003c/sub\u003e - function for modifying a response before returning it\n - `modifier` \u003csub\u003e\u003ci\u003e(object)\u003c/i\u003e\u003c/sub\u003e - object with properties `beforeSend` or/and `beforeReturn` (works the same as the functions above)\n\n## AjaxResult\n\n - `response`\n - `value` \u003csub\u003e\u003ci\u003e(object)\u003c/i\u003e\u003c/sub\u003e - `Object` containing the response to the request, or null if the request was unsuccessful or it can't be parsed as JSON\n - `document` \u003csub\u003e\u003ci\u003e(document)\u003c/i\u003e\u003c/sub\u003e - `Document` containing the response to the request, or null if the request was unsuccessful or it can't be parsed as XML or HTML\n - `text` \u003csub\u003e\u003ci\u003e(string)\u003c/i\u003e\u003c/sub\u003e - `DOMString` that contains the response to the request as text\n - `url` \u003csub\u003e\u003ci\u003e(string)\u003c/i\u003e\u003c/sub\u003e - serialized `URL` of the response or the empty string if the URL is null\n - `type` \u003csub\u003e\u003ci\u003e(string)\u003c/i\u003e\u003c/sub\u003e - value that defines the response type\n - `status` \u003csub\u003e\u003ci\u003e(number)\u003c/i\u003e\u003c/sub\u003e - unsigned short with the status of the response of the request\n - `statusText` \u003csub\u003e\u003ci\u003e(string)\u003c/i\u003e\u003c/sub\u003e - `DOMString` containing the response string returned by the HTTP server\n - `hasError` \u003csub\u003e\u003ci\u003e(boolean)\u003c/i\u003e\u003c/sub\u003e - `true` if server returned an error code\n - `headers` \u003csub\u003e\u003ci\u003e(object)\u003c/i\u003e\u003c/sub\u003e - dictionary of response headers\n\n## Examples\n\n```js\najax(\"https://api.nuget.org/v3/index.json\", {\n    statusCode: {\n        200: function(response) {\n            console.log(\"HTTP 200\");\n        }\n    },\n    success: function(response) {\n        console.log(\"Success :)\");\n    },\n    error: function(response) {\n        console.log(\"Error :(\");\n    }\n});\n```\n\n```js\najax({ url: \"https://api.nuget.org/v3/index.json\" })\n    .then(response =\u003e console.log(response.hasError ? \"Error :(\" : \"Success :)\"));\n```\n\n```js\nlet response = await ajax(\"https://api.nuget.org/v3/index.json\");\nconsole.log(response.value);\n```\n\n```html\n\u003cform action=\"https://api.nuget.org/v3/index.json\" method=\"get\"\u003e\n    \u003cinput name=\"version\" placeholder=\"NuGet version\" type=\"text\" readonly\u003e\n    \u003cinput type=\"submit\" value=\"Get NuGet version!\"\u003e\n\u003c/form\u003e\n\n\u003cscript\u003e\n    document.querySelector(\"form\").addAjax(function ({ response }) {\n        this[\"version\"].value = response.value.version;\n    },\n    {\n        // Pre-submit handler\n        // If this function will return false,\n        // request processing will be canceled\n        confirmation: () =\u003e confirm(\"Are you shure?\"),\n\n        // The time (in ms) at which repeated requests are blocked\n        interval: 500\n    });\n\u003c/script\u003e\n```\n\n## Install\n\nVia [npm](https://www.npmjs.com/package/simple-ajax-vanilla):\n\n```cmd\nnpm i simple-ajax-vanilla\n```\n\nVia [JSDelivr](https://www.jsdelivr.com/package/npm/simple-ajax-vanilla):\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/simple-ajax-vanilla/src/simpleAjax.min.js\"\u003e\u003c/script\u003e\n```\n\nManually:\n\nSimply download `simpleAjax.min.js` from the [latest release](https://github.com/Kir-Antipov/SimpleAjax/releases/latest) and add it to your project","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKira-NT%2FSimpleAjax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKira-NT%2FSimpleAjax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKira-NT%2FSimpleAjax/lists"}