使用ajax从在线站点加载json
using ajax to load json from an online site
我正在用jquery的$.ajax()
函数从另一个站点加载json。请求已成功完成,但我现在如何访问json并将其保存到javascript数组中?
$.ajax({
type:'GET',
dataType:'jsonp',
data:{},
url:'http://hawttrends.appspot.com/api/terms/',
error:function(jqXHR, textStatus, errorThrown){
console.log(jqXHR);
},
success:function(msg){
console.log(msg);
}
});
可以只遍历返回的JSON
。试试这个:
$.ajax({
type:'GET',
dataType:'jsonp',
data:{},
url:'http://hawttrends.appspot.com/api/terms/',
error:function(jqXHR, textStatus, errorThrown){
console.log(jqXHR);
},
success:function(msg){
if (msg) {
var myArray = [];
$.each(msg, function(i, item) {
//do whatever you want for each row in json
myArray.push(item);
});
}
}
});
也查看$.parseJSON(msg);
相关文章:
- AngularJS加载JSON数据,然后从中解析/加载HTML
- 在Javascript中加载JSON文件
- 如何在dojo应用程序构建概要文件中加载json文件
- 加载json时出现Ember.js和Ember数据错误
- Webgl 加载 json 模型问题
- 在AngularJS应用程序中加载JSON(加载谷歌电子表格)
- Angular $http 服务不加载 json 文件
- 在 JavaScript 中读取/加载 JSON,其中 'id' = 'x'
- 如何加载JSON数组以使用Angular-Translate翻译AngularJS网页
- 使用 jQuery 加载 JSON,然后将其显示给查看器
- D3.js可以't加载json文件
- 如何使用Angular$http.jsonp从S3加载JSON文件
- 从静态文件加载json时出错
- 如何在Fullcalendar中重新加载JSON数据
- jQuery.Dunatree.如何使用AJAX加载JSON树
- Extjs树面板未加载json数据
- AJAX加载JSON数据并将其存储在angularjs服务中
- 使用jquery加载json嵌套对象
- 如何在CasperJS脚本中通过get-int变量加载JSON
- 在我的firefox插件中加载json文件