简体   繁体   中英

Trying to .load() a public google spreadsheet

I'm trying to load a public google spreadsheet with Jq using the .load() function.

What am I doing wrong? http://jsbin.com/egetek/edit#javascript,html

$("#success").load("https://docs.google.com/spreadsheet/pub?key=0At4KrD3MMS40dFR0cm1ubGJGNnpnSWJZSVpDckpsWmc&single=true&gid=0&output=html", function(response, status, xhr) {
  if (status == "error") {
    var msg = "Sorry but there was an error: ";
    $("#error").html(msg + xhr.status + " " + xhr.statusText);
  }
});

The html:

<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
</style>
</head>
<body>
  <p id="success"></p>
  <div id="error"></div>
</body>
</html>

I would guess it is because of the same origin policy .

See the Additional Notes :

Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM