jquery - getJson 不返回任何内容

标签 jquery json getjson

我在 getJson 方面遇到了一个奇怪的问题。

例如,当我尝试使用 Nominatim 获取 json 时,如下所示:

var adresse = $('#ad').val();
$.getJSON( "http://nominatim.openstreetmap.org/search?q="+adresse+"&format=json&polygon=1&addressdetails=1", function( data ) {
    console.log(data);
}

它有效。 但如果我尝试从这样的文件中获取:

$.getJSON( "http://localhost/folder/address.json", function(data){

     console.log(data);
 });

我的 Json 文件加载良好,但数据中没有任何内容。

您能帮我找出问题所在吗?

最佳答案

检查错误:

$.getJSON('http://localhost/...', function(data){ ... })
    .done(function(){ console.log('success', arguments); })
    .fail(function(){ console.log('failure', arguments); });

您的文件可能会正确提供,它是否包含有效的 json 数据?

关于jquery - getJson 不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19425669/

相关文章:

php - 对复选框设置限制,当达到限制时提交按钮将显示 PHP 和 jQuery

javascript - python flask : How to handle send_file on the client side

c# - 当有单引号时 JsonConvert.SerializeObject 失败

javascript - getJSON 运行优先级

javascript - Jquery 为每个 HTML 字符串

jquery - 使用 jquery 从特定列表中删除背景图像

javascript - 如何来回切换插入符?

python - 将 JSON 文件转换为 numpy 数组

java - 如何缓存 Json 数据以供离线使用?

javascript - $.each() 循环中的 $.getJSON() 调用未按顺序执行