jQuery 跨域请求 JSON: 无法读取 属性 'json' of null

jQuery Cross Domain Request JSON: Cannot read property 'json' of null

我正在尝试从外部 url 获取 JSON。由于跨域问题,我使用yahoo YQL 服务。

我得到一个错误:无法读取 属性 'json' of null

感谢您的提示!

$.ajax({
    url: "http://query.yahooapis.com/v1/public/yql",
    dataType: "jsonp",
    jsonp: "callback",
    error: function() {
     alert('There is an error with rawdata');
    },
    success: function(response) {
        
  schema = [];
  object = [];
  data = [];
  
        var schema = response.query.results.json.schema;
        var options = response.query.results.json.options;
        var data = response.query.results.json.data;

        console.log( "schema: ",  schema ); // server response
        console.log( "options: ",  options ); // server response
        console.log( "data: ",  data ); // server response

         //$("#productEditor").alpaca("destroy");
      //jsonEditor(schema, options, data);

        
    }, data: {
        q: "select * from json where url=\"https://www.webongo.de/data.json?format=json?callback=?\"",
        format: "json"
    },
    
           
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

您需要在 json 响应上添加 null 检查,请参阅更新后的代码

$.ajax({
    url: "http://query.yahooapis.com/v1/public/yql",
    dataType: "jsonp",
    jsonp: "callback",
    error: function() {
     alert('There is an error with rawdata');
    },
    success: function(response) {

  schema = [];
  object = [];
  data = [];
  if(response.query.results!==null){
          var schema = response.query.results.json.schema;
          var options = response.query.results.json.options;
          var data = response.query.results.json.data;

          console.log( "schema: ",  schema ); // server response
          console.log( "options: ",  options ); // server response
          console.log( "data: ",  data ); // server response

         //$("#productEditor").alpaca("destroy");
      //jsonEditor(schema, options, data);
       }else{
            console.log("Results returns null");
       }
    }, data: {
        q: "select * from json where url=\"https://www.webongo.de/data.json?format=json?callback=?\"",
        format: "json"
    },
    
           
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>