[英]Displaying more error details
I am trying to use json data from an external provider api's. 我正在尝试使用来自外部提供商api的json数据。 When I type their json url into the browser, it shows all the json data I need to see.
当我在浏览器中输入他们的json网址时,它会显示我需要查看的所有json数据。 However, when I try to access it using jquery, I get errors, even though google chrome shows the correct json data in the dev tools section:
但是,当我尝试使用jquery访问它时,即使google chrome在“开发工具”部分中显示了正确的json数据,我也会收到错误消息:
Because of this, I assume it means that the data is actually getting retrieved? 因此,我认为这意味着实际上正在检索数据吗? Anyway, this is the script I am using:
无论如何,这是我正在使用的脚本:
$.ajax({
url: "https://some_url_here_from_different_domain.json",
type: 'GET',
dataType: 'jsonp',
jsonp: 'callback',
error: function(xhr, status, error) {
alert(error); //<- returns Error: jQuery11020135121880332008_1387982597648 was not called
alert(xhr.responseText); //<- returns undefined
},
success: function(data) {
alert("success");
}
});
How do I get further error details so I can understand what's causing the error to appear? 如何获取更多错误详细信息,以便我了解导致错误出现的原因?
Your JSONP code is fine and should work , but the endpoint you're calling in the example is returning JSON instead of JSONP regardless of your code. 您的JSONP代码很好并且可以正常工作 ,但是无论示例中的代码如何,您在示例中调用的端点都将返回JSON而不是JSONP。
Endpoint: https://localbitcoins.com/sell-bitcoins-online/national-bank-transfer/.json?callback=jQuery110202691209970507771_1387997968891&_=1387997968892 端点: https : //localbitcoins.com/sell-bitcoins-online/national-bank-transfer/.json? callback = jQuery110202691209970507771_1387997968891&_ =1387997968892
Difference: What are the differences between JSON and JSONP? 区别: JSON和JSONP有什么区别?
Possible solutions: 可能的解决方案:
So far my understanding, you want to get json data using ajax call. 到目前为止,我的理解是,您想使用ajax调用获取json数据。
According to this link - Can't get json data from jQuery ajax call 根据此链接- 无法从jQuery ajax调用获取json数据
Use dataType: 'json' instead of 'jsonp' 使用dataType:'json'代替'jsonp'
var jsonData;
$.ajax({
url: "https://some_url_here_from_different_domain.json",
dataType: 'json',
success: function(response) {
jsonData = response;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.