Javascript 带有有效Json的Json响应无效
我正在尝试对datatables和angularjs使用Ajax语法 我得到了一个无效的json响应,如下所示=Javascript 带有有效Json的Json响应无效,javascript,angularjs,ajax,datatables,Javascript,Angularjs,Ajax,Datatables,我正在尝试对datatables和angularjs使用Ajax语法 我得到了一个无效的json响应,如下所示= self.dtOptions = DTOptionsBuilder.fromSource([{ "id": 860, "firstName": "Superman", "lastName": "Yoda" }]) self.dtOptions = DTOptionsBuilder.fromSource('https://l-lin.github.io/angular-datatab
self.dtOptions = DTOptionsBuilder.fromSource([{
"id": 860,
"firstName": "Superman",
"lastName": "Yoda"
}])
self.dtOptions = DTOptionsBuilder.fromSource('https://l-lin.github.io/angular-datatables/data.json')
.withPaginationType('full_numbers');
但是我没有得到一个无效的响应,这个=
self.dtOptions = DTOptionsBuilder.fromSource([{
"id": 860,
"firstName": "Superman",
"lastName": "Yoda"
}])
self.dtOptions = DTOptionsBuilder.fromSource('https://l-lin.github.io/angular-datatables/data.json')
.withPaginationType('full_numbers');
为什么会这样?第一项是有效的json。。。核实
原样
谢谢 问题不在于json的有效性,而在于fromSource函数接受的参数类型。 尝试创建本地data.json:
[{
"id": 860,
"firstName": "Superman",
"lastName": "Yoda"
}]
然后将代码更改为
self.dtOptions = DTOptionsBuilder.fromSource('path/to/data.json');
上述答案可能有效。然而,我认为理想的答案是——我需要使用.fromFnPromise()并返回一个承诺。我目前正在调用angularjs服务,该服务使用$http.get方法生成承诺。我将研究使用$q,看看以后如何推迟承诺……是的,使用promise api可能会更好。查看重复问题的链接,您有一个如何使用$q而不是$http的示例,它相当简单和直接。祝你好运