对于我来说,我有两段代码看起来完全相同,只是它们指向两个不同的Google表格。他们都使用Tabletop.js在Google表格上运行查询。然而,第一个得到XHR错误而第二个得不到。这是非常奇怪的部分,如果我在非工作代码中的Tabletop代码中注释掉查询,那么Google Sheet中的数据会加载到页面中而不会出现错误。它似乎是挂起它的查询。所以我可以得到所有行的列表但是一旦我查询工作表,没有数据和XHR错误。
任何人都知道为什么会发生这种情况?
$(document).ready(function(){
// if firstname and surname are not passed as parameters, exit function
if (location.search.indexOf('firstname') == -1 || location.search.indexOf('surname') == -1 || $(".client-result").length == 0)
{
return;
}
var public_spreadsheet_url = 'https://docs.google.com/a/organisationname.org/spreadsheets/d/sheet_id_number/pubhtml';
// Extracting the name from the URL query string
var toFirstName = location.search.slice(11);
var whereIsAmpersand = toFirstName.indexOf('&');
var clientFirstName = toFirstName.slice(0,whereIsAmpersand);
var whereIsEqual = toFirstName.indexOf('=');
var clientSurname = toFirstName.slice(whereIsEqual + 1);
Tabletop.init( { key: public_spreadsheet_url,
callback: showInfo,
simpleSheet: true,
query: "firstname = " + clientFirstName + " and surname = " + " " + clientSurname,
})
function showInfo(data, tabletop) {
var template = $.templates("#clientTmpl");
var htmlOutput = template.render(data);
$(".client-result").html(htmlOutput);
}
});
上面的代码是非工作代码
这是工作中的
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var notEmpty = [function(arr) {
return arr.length > 0;
}, "Can't be empty."];
var TangoSchema = new Schema({
title: { type: String, required: true },
sims: { type: [SimSchema], required: true, validate: notEmpty },
statements: { type: [StatementSchema], required: true, validate: notEmpty }
});
var SimSchema = new Schema({
name: { type: String, required: true, maxlength: 5 },
description: { type: String, required: true, maxlength: 140 }
});
var StatementSchema = new Schema({
text: { type: String, required: true },
children: { type: [StatementSchema], required: true, validate: notEmpty },
focus: { type: Boolean, required: true },
childrenHidden: { type: Boolean, required: true },
simId: { type: Number, required: true }
});
exports.TangoSchema = TangoSchema;
exports.SimSchema = SimSchema;
exports.StatementSchema = StatementSchema;
错误:
XMLHttpRequest无法加载$stickyState.reset('...')。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许原点“https://spreadsheets.google.com/feeds/worksheets/the_sheet_id_number/public/basic?alt=json”访问。
答案 0 :(得分:0)