我正在寻找使用jquery / javascript的方法,在执行表单操作后将用户重定向到不同的URL。它调用写入谷歌电子表格的appscript网址。我想要的是将用户重定向到我选择的特定网址。例如。 https://www.google.com或类似。以下是我的表格:
<form action="https://script.google.com/macros/s/AKfycbwg0ASXLu-2awVG_F02o5S1u1pUyrYNHaAQvxzrObFj-47vFE8/exec"
id="courses" method="post" name="courses">
<h4>
Content Survey
</h4>
<fieldset>
<legend><span class="number">1</span> Module Info</legend> <input name=
"name" type="hidden" value="module1"> <input name="product"
type="hidden" value="XXX"> <label>Select which module you wish to
rate:</label> <select id="courses" name="clearness">
<option value="extremely_clear">
5: Extremely clear
</option>
<option value="moderately_clear">
4: Moderately clear
</option>
<option value="clear_nor_unclear">
3: Neither clear, nor unclear
</option>
<option value="moderately_unclear">
2: Moderately unclear
</option>
<option value="extremely_unclear">
1: Extremely unclear
</option>
</select> <label>Please rate the clarity of the content:</label>
</fieldset>
<fieldset>
<legend><span class="number">2</span> Additional Info</legend> <label>Was
this module helpful?</label> <select id="courses" name="helpful">
<option value="yes">
Yes
</option>
<option value="no">
No
</option>
</select>
</fieldset><input type="submit" value="Apply">
</form>
我找到了solution,但无法使其正常工作。任何人对我如何处理这个问题都有任何想法?
问候。
答案 0 :(得分:0)
一种解决方案是使用ajax提交表单,然后重定向用户。见the docs
答案 1 :(得分:0)
var url = "https://script.google.com/macros/s/AKfycbwg0ASXLu-2awVG_F02o5S1u1pUyrYNHaAQvxzrObFj-47vFE8/exec";
$.fn.serializeArray= function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
var data = $("form").serializeArray();
var success = function() {
window.location.href = "http://www.google.com";
}
$("input[type=submit]").click(function(e){
$.post(url, data, success);
e.preventDefault();
});