【问题标题】:JQuery.getJSON method is not workingJQuery.getJSON 方法不起作用
【发布时间】:2015-09-17 19:28:59
【问题描述】:

我只是想获取一个 JSON 文件,并在读取它时尝试显示警报。

我的代码如下 http://jsbin.com/winogafoqa/edit?html,js,console

$url = "http://www.googleapis.com/freebase/v1/text/en/bob_dylan?jsoncallback=?";

document.onload(
  function() {
    $.getJSON($url, function(result) {
      alert("success");
    });
  });
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>

<body>

</body>

</html>

但我没有收到任何警报消息。 我错过了什么吗?

【问题讨论】:

  • 显然会为我抛出错误。请发布有问题的相关代码。我们不应该去现场查看您的代码。问题应该是独立的,并使用演示作为附加组件
  • 如果您将网址粘贴到浏览器中,您会得到:{"error":{"errors":[{"domain":"global","reason":"sslRequired","message":"SSL is required to perform this operation."}],"code":403,"message":"SSL is required to perform this operation."}}
  • 要查询的 google 需要 ssl 连接。因此,将 URL 更改为 https:// 。查看我的答案以获取更多详细信息

标签: jquery json google-api getjson freebase


【解决方案1】:

要下载该 JSON,需要 ssl 连接。您需要包含 jQuery,并正确使用它。

$(document).ready... 是正确的语法。

一定要查询正确的url,即:https://www.googleapis.com/freebase/v1/text/en/bob_dylan?jsoncallback=?(注:https)

检查这个工作示例:https://jsfiddle.net/s1f56o54/2/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    相关资源
    最近更新 更多