【发布时间】:2023-03-19 17:53:02
【问题描述】:
可能重复:
Can’t get correct return value from an jQuery Ajax call
How to return the response from an AJAX call from a function?
我有这个:
get_json = (url) ->
$.getJSON "#{url}.json", {}, (json, response) ->
return json
但这编译为:
getJson = function(url) {
return $.getJSON("" + url + ".json", {}, function(json, response) {
return json;
});
};
..并返回响应对象。我怎样才能只返回 json?
【问题讨论】:
-
和上面提到的问题不同,这个问题是coffescript -> js转换的问题
-
这是在开玩笑吗?问题在于coffeescript 'returning' $.getJSON。其他问题没有回答这个问题。
-
删除了 jquery 标签,这样人们就不会感到困惑了。问题是coffeescript默认返回响应对象,我不知道如何防止。
-
问题一模一样。 AJAX 是异步的。当服务器提供 JSON 时,脚本执行已经超过了该行。
-
@Zenph 我正在恢复 jQuery 标签,因为这个问题肯定是关于使用 jQuery 的
$.getJSON方法。
标签: jquery coffeescript