[英]Oboe.js - how to work with chainable method and retrieving ancestor value
[英]How to pass data to Oboe.js
最初由Sashkan在Oboe.js Github問題上提出 :
“數據”由oboe.js處理嗎?
我一直在使用雙簧管來流式處理來自API的響應。 所有不需要參數的調用都可以很好地工作,但是如何使用依賴於參數的調用呢?
// basic ajax request for my call is
$.ajax({
dataType: "json",
url: url,
data: data,
success: success
});
// 'data' is my parameters list, as a json string. How can I pass it to oboe ?
oboe(url)
.done(function(things) {
alert('success');
console.log(things);
})
.fail(function(test) {
alert( "ERROR: " + test );
console.log(test);
});
正確的答案是:
oboe({
'url': url,
'method': 'POST', //optional
'body': data //no need to encode, the library will JSON stringify it automatically
}).on('done',function(things){
//do something with things
});
如果有人正在尋找一種使用可緩存的GET請求來實現RESTful的方式,則只需將查詢參數添加到URI即可,如下所示:
var query = $.param(data);
oboe(url+"?"+query)
.done(function(things) {
alert('success');
console.log(things);
})
.fail(function(test) {
alert( "ERROR: " + test );
console.log(test);
});
請注意,我正在使用JQuery
JuanCaicedo提供的答案
您可以將配置對象傳遞到oboe函數中,將數據作為請求主體傳遞(您可能必須根據API的期望對其進行格式化)。 您可以在http://oboejs.com/api中找到更多詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.