【发布时间】:2015-10-22 22:10:57
【问题描述】:
我正在尝试使用 Ajax 获取数据。
数据是json。我使用jquery 和angular。
但结果是未定义或错误。
这是我的 jquery 代码:
$(document).ready(function() {
var url = "http://market.dota2.net/history/json/";
$.ajax({
type: 'GET',
url: url,
async: false,
contentType: "application/json",
dataType: 'jsonp',
success: function(data) {
console.log(data);
}
});
});
在 Angular 中,我使用的是 jsonp 方法。怎么了?
顺便说一句,在纯 Java 中我可以从这个 url 获取数据...
【问题讨论】:
-
您确实了解 JSON 和 JSONP 之间的区别,对吧?您的示例中的 URL不返回 JSONP。
-
contentType: "application/json",— 您正在发出 GET 请求,您没有请求正文来描述其内容类型。
标签: javascript jquery json angularjs jsonp