1
我的最終問題是爲什麼我的響應打印到控制檯,但不寫入屏幕?我按照這個帖子的指示:How do I return the response from an asynchronous call?,我按照我認爲應該的方式執行回調。捕獲對jQuery的異步響應
但我所有的努力,到目前爲止已經未定義或「的翻譯:」
function myCallback(result) {
\t \t document.write(result); //prints [object Object]
\t \t console.log(result); //prints all response data to console
}
foo(myCallback);
function foo (callback){
\t $.ajax({
\t \t url: 'https://' + company + '.teamwork.com/' + action,
\t \t headers: {"Authorization": "BASIC " + window.btoa(key)},
\t \t processData: true,
\t \t data: {},
\t \t dataType: 'json',
\t }).done(function(response){
\t \t callback(response);
})
}
只是使用'response.todo您的回調中的「-items」 – Yaser
我也試過。我收到一個'Uncaught ReferenceError:items is not defined'消息。我猜連字符會把它扔掉? –
試試這個:'callback(response ['todo-items'])' – Yaser