Using jQuery getJSON Method

I am trying to pase JSON data using jQuery getJSON function. REST request:

http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%20%3D%20%22london%22&format=json&jsoncallback=?

The script I use to analyze the “data” to get the WOEID value does not seem to work below:

 $.getJSON("http://query.yahooapis.com/v1/public/yql?"+
                "q=select%20woeid%20from%20geo.places%20where%20text%20%3D%20%22"+
                "london"+
                "%22&format=json&jsoncallback=?",
        function(data){
  console.log("json: " + data);
  var datatmp = data;
          if(data.results[0]){
            var data = filterData(data.results.place[0]);
           }
         }
       );

Can anyone tell me what I'm doing wrong? link text

+3
source share
4 answers

Your code needs several settings, the version is updated here:

$.getJSON("http://query.yahooapis.com/v1/public/yql?"+
      "q=select%20woeid%20from%20geo.places%20where%20text%20%3D%20%22"+
      "london"+
      "%22&format=json&jsoncallback=json",
      function(data){
          if(data.query.results){
              $.each(data.query.results.place, function(i, v) {
                  console.log("woeid #" + i + ": " + v["woeid"]);
              });
          }
      });​

results query, , woeid ... , , woeid, , , . .

+6

:

      if(data.results[0]){
        var data = filterData(data.results.place[0]);
       }

, results[0], . , , :

      if(data.results[0]){
        var data = filterData(data.results[0].place[0]);
       }
+3

:

  • URL- YQL callback, jsoncallback
  • data.query.results…, data.results…

, data.query.count, YQL, , .

+3

I have a question: can you access this URL ( http://query.yahooapis.com/ ... ) Even if it is not in your domain? Doesn't that violate "the same origin policy"?

+2
source

Source: https://habr.com/ru/post/1740400/


All Articles