当前使用SuperAgent构造查询字符串的机制是什么
What is the current mechanism to construct a query string with SuperAgent?
我正在尝试使用SuperAgent.data()为每个文档构造一个查询字符串。但是.data()似乎已不存在。
superagent
.get(URL)
.data({ 'screen_name': USER, 'count': '1' })
.end(function(response){
if (response.ok) {
console.log('yay got ' + JSON.stringify(response.body));
} else {
console.log('Oh no! error ' + response.text);
}
});
结果:
Object #<Request> has no method 'data'
尝试用.send
替换.data
基于来源中的评论:
/**
* Send `data`, defaulting the `.type()` to "json" when
* an object is given.
*
* Examples:
*
* // querystring
* request.get('/search')
* .send({ search: 'query' })
* .end(callback)
*
* // multiple data "writes"
* request.get('/search')
* .send({ search: 'query' })
* .send({ range: '1..5' })
* .send({ order: 'desc' })
* .end(callback)
*
* // manual json
* request.post('/user')
* .type('json')
* .send('{"name":"tj"})
* .end(callback)
*
* // auto json
* request.post('/user')
* .send({ name: 'tj' })
* .end(callback)
*
* // manual x-www-form-urlencoded
* request.post('/user')
* .type('form')
* .send('name=tj')
* .end(callback)
*
* // auto x-www-form-urlencoded
* request.post('/user')
* .type('form')
* .send({ name: 'tj' })
* .end(callback)
*
* @param {String|Object} data
* @return {Request} for chaining
* @api public
*/
上面的答案在最新版本的SuperAgent(0.18.0)中对我不起作用。我不得不使用query
函数(http://visionmedia.github.io/superagent/#query-字符串)。
request.get("/search").query({ search: 'query' }).end(callback);
相关文章:
- 如何有效地将游戏数据存储在URL查询字符串中
- 从查询字符串参数推断出正确的数据类型
- AngularJS:获取链接中没有哈希的查询字符串值
- AngularJS,如何更改查询字符串
- Datatables查询url字符串:需要regex来修复url解析
- 如何将activeadmin查询字符串传递给batch_action
- 如何从查询字符串中的输入字段发回文本
- Django在使用AJAX时没有接收到新的查询字符串
- 使用查询字符串方法清除浏览器缓存
- 用于刷新的Javascript更改查询字符串
- 我想将查询字符串变量添加到JSON名称/值对中
- 将查询字符串值从页面传递 asp.net 到 iframe
- jqueryajax生成查询字符串,如果未定义则不通过
- 如何将查询字符串传递到HTML框架
- iron路由器将参数添加到字符串中,并添加一个查询
- 使用字符串查询此选择器
- 替换URL'中的字符串查询;s与Javascript(有条件)
- 基于匹配或正则表达式的查询字符串查询Mongo
- 简单json字符串查询
- 向Django传递一个布尔字符串查询