jQuery:getJSON请求不起作用

use*_*724 4 jquery getjson

我试图使用jquery的getJSON函数访问数据,但无法成功.

这是我的js文件:

$(document).ready(function(){
  $("button").click(function(){

    $.getJSON( "https://www.bitstamp.net/api/eur_usd/", function( data ) {
    alert(data);
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

能有人帮助我完成这项工作吗?

真的很感激.

小智 9

尝试在ajax调用中有错误消息

$(document).ready(function() {
        $("button").click(function() {

            $.getJSON("https://www.bitstamp.net/api/eur_usd/", function(data) {
                    alert(data);
                }
                .error(function(xhr) {
                    alert(xhr)
                })
            );
        });
    });
Run Code Online (Sandbox Code Playgroud)

注意:Xhr.responseText将为您提供错误的堆栈跟踪,它以html格式返回