我遇到了ajax请求的问题。
我使用以下代码调用时间API。这可以正常工作:
$.ajax({
async: true,
url: 'http://json-time.appspot.com/time.json?tz=GMT&callback=?',
dataType: 'jsonp', //We can only access this page API via JSONP
success: function (data) {
console.log(data.hour + ':' + data.minute + ':' + data.second);
}
});
有时我会刷新页面,它会抛出以下错误(对象):
TypeError: undefined is not a function
如果我将上面的代码更改为。它不会发生:
$.ajax({
async: false,
url: 'http://json-time.appspot.com/time.json?tz=GMT&callback=?',
dataType: 'jsonp', //We can only access this page API via JSONP
success: function (data) {
console.log(data.hour + ':' + data.minute + ':' + data.second);
}
});
干杯
答案 0 :(得分:0)
我认为这段代码是正确的,您的代码没有问题 我会在浏览器中尝试您的代码并且它没有显示您刚刚描述的错误
我得到的回应是:13:11:14 我的代码中没有遇到这样的错误......但如果你坚持错误那么 我认为问题在于你的变量字段,它似乎是一个json数据