使用ajax get从Google电子表格中检索数据

时间:2017-03-01 08:07:38

标签: javascript jquery ajax get google-sheets

我正在尝试使用此代码在我已发布的Google电子表格中获取数据。此外,我在电子表格的共享属性中选择了“任何人都可以编辑”选项。我给出了正确的网址...但是仍然有错误。希望有人可以帮助我...

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            console.log("working");
            $("#btnsubmit").click(function () {
                console.log("click working");
                $.ajax({
                    type: "GET",
                    url: "https://docs.google.com/spreadsheets/d/1fZM17gx-wo7PQIxHGe6kM4Wv1f2a-5sGhcnjGTCf5Bk/pubhtml",
                    data: "task=addNewInfo&" + $('#regForm').serialize(),
                    contentType: "application/json; charset=utf-8",
                    dataType: "html",
                    success: function (data, status) {
                        alert(data);
                        alert(data.ip);
                    },
                    error: function (xqhr, error, exception) {
                        alert("error");
                    }
                });

                });
                             
            });
    </script>
</head>
<body>
    <input type="button" value="submit" id="btnsubmit" />
</body>
</html>

1 个答案:

答案 0 :(得分:0)

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-sheetrock/1.1.4/dist/sheetrock.min.js"></script>
    <script>
        $(document).ready(function () {
            var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/1fZM17gx-wo7PQIxHGe6kM4Wv1f2a-5sGhcnjGTCf5Bk/edit#gid=0'; 
            $('#tab').sheetrock({
                url: mySpreadsheet
            });
            $('tab tr td').each(function () {

                                 
                });
                });

    </script>
    <table id="tab" style="display: none;"></table>
</body>
</html>