我是Coffeescript的新手,我有一个关于Ajax的问题。CoffeeScript ::我不知道为什么使用ajax时返回函数体
jQuery ->
api =
getId: ->
res = []
$.ajax
dataType: "jsonp"
url: "http://localhost:3004/videos.json"
success: (data) =>
if data
data.forEach (elem) =>
embed_id = elem.video_id
res.push(embed_id)
console.log res
return res
我试试这个代码,然后
console.log res
输出
["id1","id2","id3",...] .
因此,我希望api.getId()
返回["id1","id2","id3",...]
相反,我看到
Object
-> abort
function(a) {...}
...
-> status: 200
...
-> success: function(){...}
在我的调试窗口中。
我想返回响应的值。