JS:Uncaught TypeError:getJsonData不是函数

时间:2017-05-10 07:16:54

标签: javascript jquery json

我有一个从url

获取json数据的函数

代码:

 var getJsonData = function(uri,callback){
    $.ajax({
      type: "GET",
      dataType: "jsonp",
      url: uri,
      jsonpCallback: 'response',
      cache: false,
      contentType: "application/json",
      success: function(json){
        console.log(json);
        callback(json);
      }
    });
  }

这就是我调用函数的方法

    var uri = "https://192.168.236.33/conference/sched_participants/0090000146/0090001947/186";
    getJsonData(uri, function(res){
      console.log(res);
    });

但它在控制台上给了我这个错误 enter image description here

可能出现的问题是什么?

谢谢

1 个答案:

答案 0 :(得分:0)

这应该有效,这是一个工作片段

var getJsonData = function(uri, callback) {
  $.ajax({
    type: "GET",
    dataType: "jsonp",
    url: uri,
    jsonpCallback: 'response',
    cache: false,
    contentType: "application/json",
    success: function(json) {
      callback(json);
    }
  });
}

// On document ready
$(function() {
  var uri = "https://jsonplaceholder.typicode.com/users";
  getJsonData(uri, function(res) {
    $(".loader").hide();
    console.log(res);
  });
});
<!DOCTYPE html>
<html>

<head>
  <script data-require="jquery@3.1.1" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>

<body>
  <h1>Hello Plunker!</h1>
  <div class="loader">Please wait... Loading JSON data...</div>
</body>

</html>