【发布时间】:2013-11-17 17:32:18
【问题描述】:
我正在尝试将 AJAX 请求的响应数据加载到可淘汰的可观察数组中。
这是我的 AJAX 请求:
self.loadAssets = function(projectId) {
$.ajax({
url: "/Assets/getJson/"+projectId,
dataType: 'json',
success: function(json_data){
console.log(json_data);
alert('success');
$.each(json_data['getassets'], function(){
viewModel.addAsset(this.type, this.content, 'user-'+this.type, this.width, this.height, this.top, this.left);
});
}
});
};
在inspector中,我可以看到对“/Assets/getJson/id”的请求是成功的(200码) 但是从不调用警报??
我花了一整天的时间查看示例和教程,但我无法弄清楚我做错了什么。
我的 Json 文件如下所示:
{
"getassets":[
{
"id":1,
"type":"Text",
"content":"[Your Text]",
"width":"200",
"height":"100",
"top":"0",
"left":"0",
"selected":true
},
{
"id":2,
"type":"Text",
"content":"[Your Text]",
"width":"200",
"height":"100",
"top":"100",
"left":"200",
"selected":true
},
{
"id":3,
"type":"Text",
"content":"[Your Text]",
"width":"200",
"height":"100",
"top":"0",
"left":"0",
"selected":true
},
]
}
【问题讨论】:
-
尝试添加错误处理程序,可能是您收到不正确的json。
标签: javascript jquery ajax json knockout.js