Javascript 将Ajax响应数据加载到敲除数组中

Javascript 将Ajax响应数据加载到敲除数组中,javascript,jquery,ajax,json,knockout.js,Javascript,Jquery,Ajax,Json,Knockout.js,我试图将AJAX请求的响应数据加载到一个击倒可观察数组中 这是我的AJAX请求: self.loadAssets = function(projectId) { $.ajax({ url: "/Assets/getJson/"+projectId, dataType: 'json', success: function(json_data){ console.log(json_data); alert('success

我试图将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 
    }, 
]
}

我曾多次看到这种情况发生在内容类型不匹配的地方

检查输出的内容类型是否设置为application/json

还要添加到ajax调用中

contentType: "application/json"

尝试添加错误处理程序,可能您收到的json不正确。