[英]My API Call Isn't Returning Anything?
I'm checking to see if a Twitch.com user has ever existed. 我正在检查Twitch.com用户是否曾经存在。 When I check the API call it is returning a value in the browser, but not in the console.
当我检查API调用时,它在浏览器中返回一个值,但在控制台中未返回。
$.getJSON("https://api.twitch.tv/kraken/channels/comster404", function(data2){
// console.log(data2.status);
console.log(data2);
});
This is the data it should get { "error": "Unprocessable Entity", "status": 422, "message": "Channel 'comster404' is not available on Twitch" } 这是应该获取的数据{“” error“:” Unprocessable Entity“,” status“:422,” message“:” Twitch上的频道'comster404'不可用“}
You've passed a success
callback but no error
callback. 您已经传递了
success
回调,但没有error
回调。 Since an error occurred when fetching that URL, the success
callback would not be called. 由于获取该URL时发生错误,因此不会调用
success
回调。
You can set the callbacks for success
and error
with done()
and fail()
respectively: 您可以分别使用
done()
和fail()
设置success
和error
的回调:
var log = document.getElementById("log"); $.getJSON("https://api.twitch.tv/kraken/channels/comster404") .done(function(data) { console.log(data); log.innertHTML += "success!"; }) .fail(function(error) { console.log(error); log.innerHTML += error.responseText; });
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script> <div id="log"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.