0
我想知道是否有可能使提交表單按鈕採取多種行動。目前我正在使用自定義表單,它將使用AJAX發送到Google Spreadsheet。我也使用Blueimp Jquery File Upload插件。我所希望的是,可以將所有相關信息發送到Google Spreadsheet並將上傳的圖像發送到我的服務器。我願意接受任何不涉及Blueimp Jquery Upload的潛在解決方案,我正在使用Google Spreadsheets來允許多個協作者訪問數據。可能使表單按鈕執行多個操作?
對於遺漏的任何細節,我表示歉意,因爲我對文件上傳並不熟悉,但請詢問我將盡我所能提供任何和所有相關信息。
谷歌電子表格提交代碼:
// Handle form submission
$('form').submit(function(e) {
var button = $('input[type=submit]', this),
data = $(this).serialize();`
e.preventDefault();
if (validate($(this))) {
button.button('loading');
$.ajax({
type: 'POST',
url: formUrl,
data: data,
complete: function() {
button.button('reset');
window.location = 'index.html#new';
}
});
}
function validate(form) {
$('.control-group').removeClass('error');
$('input, textarea', form).each(function() {
var tag = $(this)[0].tagName.toLowerCase(),
type = $(this).attr('type');
// Validate radio buttons
if (tag === 'input' && type === 'radio') {
var name = $(this).attr('name');
if ($('[name="' + name + '"]:checked').length < 1) {
$(this).parent().parent().parent().addClass('error');
}
}
// Validate text fields
if ((tag === 'input' && type === 'text') || tag === 'textarea') {
if ($(this).val() === '' && !$(this).parent().hasClass('radio')) {
$(this).parent().parent().addClass('error');
}
}
});
if ($('.control-group.error').length < 1) return true;
$('.control-group.error').length
$('html, body').animate({
scrollTop: $('.control-group.error').offset().top - 20
}, 500);
return false;
}
});
謝謝我會試試看! –