编写google docs表单提交脚本 [英] scripting a google docs form submission
问题描述
我正在尝试创建一个书签页,该书签页可以解析页面并将结果通过我定义的表单发送到googledocs电子表格.
I'm trying to create a bookmarklet that parses a page and sends the results to a googledocs spreadsheet via a form that I've defined.
脚本的相关位是:
var form = document.createElement("form");
form.action = "http://spreadsheets.google.com/formResponse?formkey=Fd0SHgwQ3YwSFd5UHZpM1QxMlNOdlE6MA&ifq";
form.method = "POST";
form.id="ss-form";
form.innerHTML = ["<input id='entry_0' name = 'entry.0.single' value = '" + orderDate + "'/>", "<input name = 'entry.2.single' value = '" + email + "'/>", "<input name = 'entry.3.single' value = '" + customerID + "'/>", ].join("");
form.submit();
alert(form.innerHTML);
//返回:
没有通过书签保存到表单中的内容-用我的书签的代码捕获Google响应的任何方法吗? (首先,我已经通过jQueryify注入了jQuery)
Nothing is being saved to the form via the bookmarklet - any way to capture google's response in my bookmarklet's code? (fwiw, i've injected jQuery via jQueryify)
Firebug的网络"面板没有听到由书签触发的任何活动-我如何通过goolgle的 viewform 方法而不是 formresponse 来实现此目的.
Firebug's Net panel isn't hearing any of the activity triggered by the bookmarklet - How about i approach this from goolgle's viewform method instead of formresponse.
我要提交的表单位于:
http://spreadsheets.google.com/viewform?hl=zh_CN& formkey = dFd0SHgwQ3YwSFd5UHZpM1QxMlNOdlE6MA
我如何才能将脚本值注入该表单中,然后再次提交-通过...在被解析的页面上触发的书签小脚本中的脚本再次提交?
How can I go about injecting the script values into that form and then submitting that - again...via script within the bookmarklet that would have been triggered while on the page being parsed?
推荐答案
如果您已经在使用jquery,请尝试通过ajax($ .ajax)提交表单.您可以设置一个成功函数,当google发回他们的响应时将调用该函数.
if your already using jquery, try submitting the form via ajax ($.ajax). You can setup a success function that will be called when google sends back their response.
或者,您应该可以使用Firebug查看google发送回的响应.
alternatively you should be able to use firebug to view the response google sends back.
具体地说,我认为您可以尝试以下操作:
Specifically I was thinking you could try something like the following:
$.ajax({
url: "http://spreadsheets.google.com/formResponse",
data: { formkey: "Fd0SHgwQ3YwSFd5UHZpM1QxMlNOdlE6MA&ifq", "entry.0.single": orderDate, "entry.2.single": email, "entry.3.single": customerID },
type: "POST",
dataType: "xml",
success: function(data, textStatus, XMLHttpRequest) {
console.log("success");
console.log(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("error");
console.log(textStatus);
},
})
这篇关于编写google docs表单提交脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!