【发布时间】:2014-11-12 23:33:17
【问题描述】:
我试图在 html 中显示我在 app.js 中收到的 json,但它不起作用。有什么想法吗?
app.js 的代码(我确定 $.post 返回一个有效的 json)
App.CadeirasRoute = App.AuthenticatedRoute.extend({
model: function() {
alert(this.getUsername());
$.post('/api/database/cadeira/', {"token": this.postJSONWithToken()}).then(function(response) {
if (response.success) {
alert(response.results[0].codigo); // this alerts right on browser with the right value of codigo of the first json in the array
return response.results;
}
});
}
});
我的 html 代码
<script type="text/x-handlebars" id="cadeiras">
<div id="cadeiras">
{{#each item in model}}
<h2>{{item.codigo}}</h2>
{{/each}}
</div>
</script>
【问题讨论】:
-
你能贴出 JSON 响应的代码吗?
标签: jquery html ajax json ember.js