SuperAgent輕量的Ajax API
SuperAgent 是一個(gè)輕量的Ajax API,服務(wù)器端(Node.js)客戶(hù)端(瀏覽器端)均可使用,SuperAgent具有學(xué)習(xí)曲線低、使用簡(jiǎn)單、可讀性好的特點(diǎn),可作為客戶(hù)端請(qǐng)求代理模塊使用,當(dāng)你想處理get,post,put,delete,head請(qǐng)求時(shí),可以考慮使用SuperAgent。
瀏覽器支持:
request
.post('/api/pet')
.send({ name: 'Manny', species: 'cat' })
.set('X-API-Key', 'foobar')
.set('Accept', 'application/json')
.end(function(err, res){
if (res.ok) {
alert('yay got ' + JSON.stringify(res.body));
} else {
alert('Oh no! error ' + res.text);
}
});
SuperAgent請(qǐng)求的默認(rèn)方法為GET,所以你可可以簡(jiǎn)單地寫(xiě)如下代碼:
request('/search', function(res){
});評(píng)論
圖片
表情
