2013-01-17 71 views
0

在CoffeeScript中,我使用这个加载一个JSON文件获取JSON数据对象具有的CoffeeScript和jQuery

$.ajax 'json/data.json', 
     success : (res, status, xhr, data) -> 
      console.log("yea "+data) 
     error : (xhr, status, err) -> 
      console.log("nah "+err) 
     complete : (xhr, status) -> 
      console.log("comp") 

文件加载,但数据出现是不确定的?

+0

你确定服务器发回的数据? –

回答

1

成功来自不同的参数集:

success 
Type: Function(Object data, String textStatus, jqXHR jqXHR) 

试试这个:

$.ajax 'json/data.json', 
     success : (data, status, xhr) -> 
      console.log("yea "+data) 
     error : (xhr, status, err) -> 
      console.log("nah "+err) 
     complete : (xhr, status) -> 
      console.log("comp")