Problem getting query from google fusion tables

I'm having trouble finding Google Fusion spreadsheets using an HTTP request. If I paste the URL from the request below in the browser, it returns with a comma separated list. However, when I do this using the .get function, as shown below, nothing is returned in the data parameter.

I am new to this, so any help would be greatly appreciated.

function query(){
var jqxhr=$.get(
    "https://www.google.com/fusiontables/api/query?sql=SELECT+Address+FROM+914142+WHERE+IsCustomer+%3D+1",
    function success(data, textStatus){
alert(data);})}
+3
source share
5 answers

I struggled with this for some time, and only this afternoon posted sample code and working example of how to handle requests Fusion Tables.

, (http://en.wikipedia.org/wiki/Same_origin_policy), - "jsonp" $.get. jQuery.get.

:

function query(){
    var queryurl = "<your query url>";
    querytail = "&jsonCallback=?";

    var jqxhr=$.get(queryurl + querytail, queryHandler, "jsonp")
}

function queryHandler(data) {
    // display the first row of retrieved data
    alert(data.table.rows[0]);
}
+6

, Google - .

- - ( , , ), JSONP.

jsonCallback=<callback name here> Fusion Tables, JSONP. , :

https://www.google.com/fusiontables/api/query?sql=SELECT+Address+FROM+914142+WHERE+IsCustomer+%3D+1&jsonCallback=foo

:

foo({"table":{"cols":["Address"],"rows":[["3400 California Street, Suite 302, San Francisco, CA 94118"],["1200 Pacific Avenue, San Francisco, CA 94109"],["340 10TH Street, San Francisco, CA 94103"],["One Embarcadero Center, Lobby Level, San Francisco, CA 94111"],["2230 Third Street, San Francisco, CA 94107"],["490 Post St, Suite 430, San Francisco, CA 94102"],["530 Bush St. Suite 101, San Francisco, CA 94108"],["114 Sansome Street, Suite 715, San Francisco, CA 94104"],["3012 Steiner Street Suite A, San Francisco, CA 94123"],["199 Fremont St # 105, San Francisco, CA 94105"],["2007 Irving St., San Francisco, CA 94122"],["450 Sutter Suite 2518, San Francisco, CA 94108"],["275 Gough Street, San Francisco, CA 94102"],["450 Sutter Street Suite 1225, San Francisco, CA 94108"],["2675 Geary Blvd., Ste 400, San Francisco, CA 94118"],["332 Pine St # 505, San Francisco, CA 94104"]]}})

IBM JSONP : http://www.ibm.com/developerworks/library/wa-aj-jsonp1/

0

JSONP :

function processData(json){
  for (var i, row; row=json.table.rows[i]; i++){
    console.log(row)
  }
}

script = document.createElement("SCRIPT")
script.src = "https://www.google.com/fusiontables/api/query?sql=SELECT+Address+FROM+914142+WHERE+IsCustomer+%3D+1&jsonCallback=processData";
document.getElementsByTagName("HEAD")[0].appendChild(script);

, ? , lib - .

0

, , - , , .

, php script,

<?php echo file_get_contents('http://www.sameoriginpolicydomain.com'); ?>

, AJAX, . :

<?php echo file_get_contents('http://www.google.com/fusiontables/exporttable?query='.urlencode($_GET['query']).'&o=kmllink&g='.$_GET['g']); ?>
0

noiv11 , , , JSONP. , cURL , , .

PHP-, : Fusion Tables Client PHP

0
source

All Articles