{"id":20420320,"url":"https://github.com/deepraining/see-ajax","last_synced_at":"2026-05-01T20:31:52.492Z","repository":{"id":57356496,"uuid":"86392651","full_name":"deepraining/see-ajax","owner":"deepraining","description":"一个 ajax 封装器, 能够对响应 Json 对象进行重构, 预处理请求对象, 后置处理响应数据等. An ajax wrapper, with response refactoring, pre handling, post handling, etc.","archived":false,"fork":false,"pushed_at":"2020-01-14T08:01:47.000Z","size":271,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-14T09:02:22.475Z","etag":null,"topics":["ajax","handle","jquery","json","refactor","response","wrapper"],"latest_commit_sha":null,"homepage":"","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/deepraining.png","metadata":{"files":{"readme":"README.en.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-27T23:08:48.000Z","updated_at":"2020-01-14T08:01:49.000Z","dependencies_parsed_at":"2022-09-06T03:50:19.604Z","dependency_job_id":null,"html_url":"https://github.com/deepraining/see-ajax","commit_stats":null,"previous_names":["senntyou/see-ajax","senntyou/jquery.seeajax"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/deepraining/see-ajax","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepraining%2Fsee-ajax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepraining%2Fsee-ajax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepraining%2Fsee-ajax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepraining%2Fsee-ajax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepraining","download_url":"https://codeload.github.com/deepraining/see-ajax/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepraining%2Fsee-ajax/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32512662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","handle","jquery","json","refactor","response","wrapper"],"created_at":"2024-11-15T06:42:27.195Z","updated_at":"2026-05-01T20:31:52.468Z","avatar_url":"https://github.com/deepraining.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# see-ajax\n\n[中文文档](./README.md)\n\nAn ajax wrapper, with response refactoring, pre handling, post handling, etc.\n\n## requirements\n\n- [json-refactor](https://github.com/senntyou/json-refactor)\n- [reqwest](https://github.com/ded/reqwest)\n\n## related\n\n- [see-fetch](https://github.com/senntyou/see-fetch)\n\n## note\n\nOnly for `json` response.\n\n## quick start\n\n```\nnpm install see-ajax --save\n```\n\n```\nimport seeAjax from 'see-ajax';\n\n// configure application\nseeAjax.config(name, {\n  method,\n  stringify,\n  settings,\n  url,\n  req,\n  refactor,\n  pre,\n  post,\n  implement,\n});\n\n// make a request\nseeAjax(name, params, callback);\n```\n\n## config options\n\n### `method`: which http method to use\n\n- `type`: `string`\n- `default`: `get`\n\n```\n'post/put/delete'\n```\n\n### `stringify`: whether to stringify request params\n\n- `type`: `bool`\n- `default`: `false`\n\nIf `true`, the server will receive string, but not `key-value` pairs.\n\nIf `GET` method, request params will not stringify at any time.\n\n### `settings`: extra [reqwest](https://github.com/ded/reqwest#options) options\n\n- `type`: `map`\n- `default`: `{}`\n\n### `url`: url to request\n\n- `type`: `string`\n- `default`: empty string\n\n### `req/requestKeys`: keys mapping of request params\n\n- `type`: `map`\n- `default`: `{}`\n\n```\n{sourceKey: 'newKey'}\n```\n\n### `refactor/responseRefactor`: rules to refactor response using [json-refactor](https://github.com/senntyou/json-refactor)\n\n- `type`: `map`\n- `default`: `{}`\n\n```\nrefactor: rules\n```\n\n- `rules`: see [json-refactor](https://github.com/senntyou/json-refactor)\n\n### `pre/preHandle`: more handling to request params\n\n- `type`: `function`\n\n```\n(params, name) =\u003e {... modify params, or return a new params ...}\n```\n\n### `post/postHandle`: more handling to response data\n\n- `type`: `function`\n\n```\n(result, params, name) =\u003e {... modify result, or return a new result }\n```\n\n### `implement`: custom implementing instead of `ajax`\n\n- `type`: `function`\n\n```\n(cb, params) =\u003e { ... cb(result) }\n```\n\nSometimes, you have to not use `ajax`, but other ways, like html templates.\n\n## api\n\n### `seeAjax.config`: configure application\n\n```\n// one\nseeAjax.config(name, options);\n\n// multiple\nseeAjax.config({\n  name1: options1,\n  name2: options2,\n  ...\n});\n```\n\n### `seeAjax.setEnv`: set current environment(index to get config options)\n\n```\nseeAjax.setEnv(0/1/2/3);\n```\n\nIf you need multiple environments supports, you can configure all config options by array, and then set a env.\n\nIf you don't set an environment, 0 will be the default.\n\n```\nseeAjax.config(name, {\n  method: [method1, method2, ...],\n  stringify: [stringify1, stringify2, ...],\n  settings: [settings1, settings2, ...],\n  url: [url1, url2, ...],\n  req: [req1, req2, ...],\n  refactor: [refactor1, refactor2, ...],\n  pre: [pre1, pre2, ...],\n  post: [post1, post2, ...],\n  implement: [implement1, implement2, ...],\n});\n\nseeAjax.setEnv(0); // method1, stringify1, url1, ...\nseeAjax.setEnv(1); // method2, stringify2, url2, ...\n```\n\n### `seeAjax.getEnv`: get current environment\n\n```\nconst env = seeAjax.getEnv(); // 0/1/2/3\n```\n\n### `seeAjax`: make a request\n\n```\nseeAjax(name, params, callback);\n```\n\n- `name`: defined request name\n  - `note`: `common` is a special request name, and it will apply to all requests\n- `params`: request params\n  - `type`: `map`\n  - `example`: `{a: 1, b: '2'}`\n- `callback`: callback when ajax complete\n  - `example`: `result =\u003e { ... }`\n  - `result`: handled response data. But if response's status code is `3XX, 4XX, 5XX`, `result` will be like: `{error: true, response: Response}`\n    - `error`: mark response having an error, and you can customize it by `seeAjax.set({errorField: 'yourErrorField'})`\n    - `response`: original [XMLHttpRequest Object](https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest)\n\n### `seeAjax.set`: set custom config\n\n```\nseeAjax.set({\n  errorField: 'error',\n  debug: !0,\n  disableCache: !0,\n  disableCacheField: '_',\n});\n```\n\n- `errorField`: `type: string` `default: error` configure your own error field\n- `debug`: `type: bool` `default: true` whether in debug mode\n- `disableCache`: `type: bool` `default: true` disable request cache for `GET, HEAD` methods\n- `disableCacheField`: `type: string` `default: _` field name for appending timestamp to original url when `disableCache` is `true`\n\n## handlers sequences while processing\n\n1. `method`: check which http method to use, default is `GET`\n2. `stringify`: check whether to stringify request params\n3. `settings`: check extra [reqwest](https://github.com/ded/reqwest#options) settings\n4. `url`: get request url\n5. `req`: get real request params\n6. `pre`: more handling before send a request\n   1. `common`: common handling, if have\n   2. `name`: named handling\n7. `implement`: if have, `see-ajax` will not send an `ajax`\n8. `refactor`: refactoring response data\n   1. `common`: common handling, if have\n   2. `name`: named handling\n9. `post`: more handling after refactoring response data\n   1. `common`: common handling, if have\n   2. `name`: named handling\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepraining%2Fsee-ajax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepraining%2Fsee-ajax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepraining%2Fsee-ajax/lists"}