Google-javascript visualization option

I tried using google spreadsheet to implement drop down selection! But I am facing some errors ... In the console, this shows that ...

**A Parser-blocking, cross-origin script, https://www.google.com/uds/?file=visualization&v=1&packages=corechart%2Cgeomap%2Ctable, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity.**
**A Parser-blocking, cross-origin script, https://www.google.com/uds/api/visualization/1.0/b5ac9efed10eef460d14e653d0…zh_TW,default+zh_TW,ui+zh_TW,geomap+zh_TW,table+zh_TW,corechart+zh_TW.I.js, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity.**

I try tips to fix this, but it cannot fix ... Here is the code I wrote

<html><head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type=text/javascript>
google.setOnLoadCallback(runQuery);
google.load('visualization', '1',
        {
          'packages':['corechart', 'table', 'geomap']
        }
);function runQuery() {
var tableid = '1zCrjWMRxcedcvdWWAwtc9psQoK8GoGyxy8R53Ga_ztk#gid=0';
var uri = "SELECT geometry FROM " + tableid ;
var queryText = "https://spreadsheets.google.com/tq?key=" + encodeURIComponent(uri);
var query = new google.visualization.Query(queryText);
query.setQuery("select B");
var a = query.setQuery("select B,C,D ");
query.send(function(resp){
if (!resp.isError()) {
  var dataTable = resp.getDataTable();
  var jsonData = JSON.parse(dataTable.toJSON());
  var len = jsonData.rows.length;
  console.log(len);
  alert(len);
  }
});}</script></head><body></body></html>
+4
source share
1 answer

1) the message Parser-blockingshould be just a warning.

Regardless of avoiding the message, use the loader.jslibrary to load
instead of the old libraryjsapi

you will need to change the statement loadas follows:

<script src="https://www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load('current', {'packages':['corechart', 'table', 'geomap']});
google.charts.setOnLoadCallback(runQuery);
...

...

Google Charts, jsapi, . gstatic loader.

2) , ,

. , , Access denied...

google.charts.load('current', {'packages':['corechart', 'table', 'geomap']});
google.charts.setOnLoadCallback(runQuery);

function runQuery() {
var tableid = '1zCrjWMRxcedcvdWWAwtc9psQoK8GoGyxy8R53Ga_ztk#gid=0';
var uri = "SELECT geometry FROM " + tableid ;
var queryText = "https://spreadsheets.google.com/tq?key=" + encodeURIComponent(uri);
var query = new google.visualization.Query(queryText);
query.setQuery("select B");
var a = query.setQuery("select B,C,D ");
query.send(function(resp){
if (!resp.isError()) {
  var dataTable = resp.getDataTable();
  var jsonData = JSON.parse(dataTable.toJSON());
  var len = jsonData.rows.length;
  console.log(len);
  } else {
    console.log('Error: ' + resp.getMessage() + '\nDetails: ' + resp.getDetailedMessage());
  }
});}
<script src="https://www.gstatic.com/charts/loader.js"></script>
Hide result
+4

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


All Articles