superagent-jsonp中文文档|superagent-jsonp js中文教程|解析

npm npmdoc 2年前 (2022-01-02) 1427次浏览

superagent-jsonp中文文档|superagent-jsonp js中文教程|解析

安装命令:npm i superagent-jsonp

superagent-jsonp

圆环CI
bitHound 总分

将 jsonp 行为添加到超级代理。

与 browserify 一起使用

首先使用 npm 安装

npm i superagent-jsonp --save

然后像这样使用;

const superagent = require('superagent');
const jsonp = require('superagent-jsonp');
superagent.get('http://example.com/foo.json').use(jsonp).end(function(err, res){
  // everything is as normal
});

与凉亭一起使用

首先安装:

bower i superagent-jsonp --save

以通常的方式从您的凉亭组件中包含它

然后像上面一样使用

superagent.get('http://example.com/foo.json').use(superagentJSONP).end(function(err, res){
  // everything is as normal
});

jsonp 函数的可用选项

  • callbackParam:包含要调用的函数名称的查询参数的名称。默认为callback.
  • 回调名称:可选。回调函数的名称
  • 超时:等待多长时间,直到这被认为是不成功的请求。

    • 注意:当前所有不成功的请求都被视为 404s

用法

superagent
  .get('http://example.com/obviously_404.json').use(jsonp({
      timeout: 3000,
      callbackName: 'someOtherName'
    })).end((err, response) => {
      // response => {}
      // err => new Error('404 NotFound')
    });
项目贡献人员列表:


极客公园 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:superagent-jsonp中文文档|superagent-jsonp js中文教程|解析
喜欢 (0)
.excerpt .focus {display:none}