【发布时间】:2013-03-11 19:15:03
【问题描述】:
我正在使用 $.getJSON() 并尝试使用以下各种代码返回数据:
var changeUserPage = function (id) {
return repository.getUserPage(id).done(function (data) {
// console.log(data)
})
}
问题是,虽然在 done 函数中,我可以看到我想要的正确数据,但我无法将它返回给我的调用函数,例如:
var data = dataContext.changeUserPage(lastPolicyWorkedOn);
data current 持有 Promise 对象:
Object {readyState: 1, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…}
编辑
getJSON 方法如下所示:
var getUserPage = function (policyId) {
policyId = encodeURIComponent(policyId);
var uri = "http://localhost:54997/api/policy/getUserPage/" + policyId;
return $.getJSON(uri);
}
如何最好地返回实际的 json 数据?
谢谢
戴维
【问题讨论】:
-
很难用发布的当前代码给出解决方案。您也可以发布 getJson 吗?
-
@Jai。我已经添加了 getJSON 方法。谢谢
-
好的,现在你对那个网址有什么期望?
-
如果我取消注释 console.log(data) 我可以看到 json 数据在那里并且符合预期。我儿子不知道如何将其返回给调用函数。这有意义吗?