Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery:getJSON请求不工作_Jquery_Getjson - Fatal编程技术网

jQuery:getJSON请求不工作

jQuery:getJSON请求不工作,jquery,getjson,Jquery,Getjson,我试图使用jquery的getJSON函数访问数据,但未能成功 这是我的js文件: $(document).ready(function(){ $("button").click(function(){ $.getJSON( "https://www.bitstamp.net/api/eur_usd/", function( data ) { alert(data); }); }); }); 有人能帮我完成这项工作吗 我会非常感激的 尝试在ajax调用中显示错

我试图使用jquery的getJSON函数访问数据,但未能成功

这是我的js文件:

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

    $.getJSON( "https://www.bitstamp.net/api/eur_usd/", function( data ) {
    alert(data);
    });
  });
});
有人能帮我完成这项工作吗


我会非常感激的

尝试在ajax调用中显示错误消息

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

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

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

需要使用
JSON.stringify(data)
而不仅仅是数据

我假设这是发出请求的一个外部域,在这种情况下,由于。您需要检查您查询的API是否接受JSONP请求,或者是否为CORS设置。Try using console.log(data.responseData)的可能重复项;要查看任何错误,请勾选此项