{"id":29926611,"url":"https://github.com/ecomfe/saber-ajax","last_synced_at":"2025-09-03T05:36:41.860Z","repository":{"id":9052835,"uuid":"10818999","full_name":"ecomfe/saber-ajax","owner":"ecomfe","description":"适用于移动端、promise 风格的 ajax 封装","archived":false,"fork":false,"pushed_at":"2015-07-15T06:06:47.000Z","size":431,"stargazers_count":13,"open_issues_count":3,"forks_count":6,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-08-02T12:57:52.886Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"syxolk/euro2016","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecomfe.png","metadata":{"files":{"readme":"README.md","changelog":"History.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":"2013-06-20T12:11:29.000Z","updated_at":"2022-10-08T13:43:31.000Z","dependencies_parsed_at":"2022-07-10T04:17:58.642Z","dependency_job_id":null,"html_url":"https://github.com/ecomfe/saber-ajax","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/ecomfe/saber-ajax","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsaber-ajax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsaber-ajax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsaber-ajax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsaber-ajax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecomfe","download_url":"https://codeload.github.com/ecomfe/saber-ajax/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Fsaber-ajax/sbom","scorecard":{"id":365668,"data":{"date":"2025-08-11","repo":{"name":"github.com/ecomfe/saber-ajax","commit":"097f305946d3ca78ab4b79928067e537434dd7d2"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-18T11:47:26.089Z","repository_id":9052835,"created_at":"2025-08-18T11:47:26.089Z","updated_at":"2025-08-18T11:47:26.089Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273287845,"owners_count":25078602,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"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":[],"created_at":"2025-08-02T12:42:17.918Z","updated_at":"2025-09-03T05:36:41.807Z","avatar_url":"https://github.com/ecomfe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"saber-ajax\n===\n\n![Bower version](https://img.shields.io/bower/v/saber-ajax.svg?style=flat-square) [![NPM version](https://img.shields.io/npm/v/saber-ajax.svg?style=flat-square)](https://npmjs.org/package/saber-ajax) [![Build Status](https://img.shields.io/travis/ecomfe/saber-ajax.svg?style=flat-square)](https://travis-ci.org/ecomfe/saber-ajax) [![License](https://img.shields.io/npm/l/saber-ajax.svg?style=flat-square)](./LICENSE) [![EFE Mobile Team](https://img.shields.io/badge/EFE-Mobile_Team-blue.svg?style=flat-square)](http://efe.baidu.com)\n\n适用于移动端、[Promise](https://github.com/ecomfe/saber-promise) 风格的 ajax 封装，支持 [XMLHttpRequest2](http://www.w3.org/TR/XMLHttpRequest2/)，兼容 node 环境\n\n\u003cdel\u003e以\u003ca href=\"http://baike.baidu.com/view/8420590.htm\" target=\"_blank\"\u003e吾王\u003c/a\u003e之名~\u003c/del\u003e\n\n## Installation\n\n通过 [edp](https://github.com/ecomfe/edp) 引入模块：\n\n```sh\n$ edp import saber-ajax\n```\n\n或者在 node 环境下使用 `npm` 引入模块：\n\n```sh\n$ npm install saber-ajax --save\n```\n\n## Usage\n\n```js\nvar ajax = require('saber-ajax');\n\nvar request = ajax.get(url);\n\nrequest.then(\n    // 请求完成\n    // data为responseText\n    function (data) {\n        renderData(data);\n    },\n\n    // 请求失败\n    // error参数可能为以下四种情况\n    // * 请求超时: 'timeout'\n    // * 请求中止: 'abort'\n    // * 未知错误: 'error'\n    // * 其它情况: HTTP Status Code\n    function (error) {\n        showError(error);\n    }\n);\n\n// 支持 ejson 格式的异步交互\najax = require('saber-ajax').ejson;\n```\n\n## API\n\n* [Methods](#methods)\n* [Events](#events)\n* [Classes](#classes)\n\n### Methods\n\n#### get(url[, query])\n\n发起异步GET请求\n\n* **url** `{string}` 请求地址\n* **query** `{Object=}` 查询条件，会自动进行 `encodeURIComponent` 处理\n* _return_ `{Requester}` 请求对象 [Requester](doc/requester.md)\n\n#### post(url[, data])\n\n发起异步POST请求\n\n* **url** `{string}` 请求地址\n* **data** `{Object|string=}` 请求数据，可选。使用 `{Object}` 类型时请注意：暂时只支持单一层级序列化，不支持多层级（比如 `{date: {begin: '2012', end: '2013'}}` ）\n* _return_ `{Requester}` 请求对象 [Requester](doc/requester.md)\n\n#### request(url[, options])\n\n发起请求，如果不做设置默认为 `GET` 异步请求\n\n* **url** `{string}` 请求地址\n* **options** `{Object=}` 配置参数\n    * **method** `{string=}` 请求方式，默认为 `'GET'`\n    * **data** `{string|Object=}` 请求参数，支持 [FormData](http://www.w3.org/TR/XMLHttpRequest2/#interface-formdata)\n    * **stringify** `{boolean=}` 是否自动序列化请求参数，默认为 `true`\n    * **async** `{boolean=}` 是否异步请求，默认为 `true`，出于用户体验的考虑新版的浏览器在主线程中都不再支持发起同步请求，请慎重使用此参数\n    * **headers** `{Object=}` 需要额外设置的请求头\n    * **timeout** `{number=)` 请求超时时间，单位ms，**注意** 只有异步请求才有效\n    * **username** `{string=}` 用户名\n    * **password** `{string=}` 密码\n    * **responseType** `{string=}` 返回的 [数据类型](http://www.w3.org/TR/XMLHttpRequest2/#xmlhttprequestresponsetype)，默认为空。`text` 与 `arraybuffer` 各浏览器的支持力度较好，其它选项使用前请多多思量~\n\n#### config(options)\n\n全局配置\n\n* **options** `{Object}` 配置项\n    * **host** `{string=}` host，默认为空\n    * **prefix** `{string=}` 请求路径前缀，默认为空\n    * **headers** `{Object=}` 请求头信息，默认为空\n    * **agent** `{Object=}` 请求管理对象配置信息，只针对 node 平台配置有效，具体配置项请参考 [http.Agent 的初始化说明](https://nodejs.org/api/http.html#http_new_agent_options)\n\n#### on(event, fn)\n\n注册全局事件\n\n* **event** `{string}` 事件名称，具体支持的事件[请参照事件说明](#events)\n* **fn** `{Function}` 事件处理函数\n\n可以通过注册全局事件配合 [requester.handleFail](#handlefail) 来提供默认的请求失败处理，比如：\n\n```js\nvar ajax = require('saber-ajax');\n\n// 注册全局失败事件\najax.on('fail', function (req, error) {\n    // 如果当前的失败请求没有被处理过\n    // 则显示默认的错误提示\n    if (!req.handleFail) {\n        alert('亲~请求失败啦');\n    }\n});\n```\n\n### Events\n\n#### success\n\n全局请求成功事件，任意请求成功时触发\n\n* **req** `{Requester}` 请求对象 [Requester](doc/requester.md)\n* **data** `{*}` 请求返回的内容\n\n#### fail\n\n全局请求失败事件，任意请求失败时触发\n\n* **req** `{Requester}` 请求对象 [Requester](doc/requester.md)\n* **error** `{*}` 错误信息（参考 [request.then](#then-onfulfill-onreject-) 关于错误信息的描述）\n\n### Classes\n\n * [Requester](doc/requester.md) 请求对象，`ajax.get`，`ajax.post`，`ajax.request` 等方法的返回参数，对异步请求对象的封装，实现了 [Promise](https://github.com/ecomfe/saber-promise) 接口\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fsaber-ajax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomfe%2Fsaber-ajax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Fsaber-ajax/lists"}