我有一個帶有4個標題/部分的手風琴,每個手風琴都有一個表格。我需要將每個表單提交給服務器並給出回調,以及在用戶進入流程中的下一個步驟之前進行驗證。我有驗證工作 - 我只使用默認設置。現在我如何獲得每個提交的表單的回調?我知道我需要分配每個下一個按鈕來提交,但是我不知道如何使用這個腳本來做到這一點,因爲這個腳本是爲單個表單提交的。提交每個手風琴的表格
我也不允許使用PHP,因爲這不是我們在這裏使用的東西。我們使用JSP來處理datacalls,所以請避免使用PHP響應。謝謝。
我的腳本進行驗證:
$(document).ready(function(){
// add * to required field labels
$('label.form-field-label-required').append(' <strong>*</strong>');
// accordion functions
var accordion = $("#accordion").accordion();
var current = 0;
$.validator.addMethod("pageRequired", function(value, element) {
var $element = $(element)
function match(index) {
return current == index && $(element).parents("#accordion").length;
}
if (match(0) || match(1) || match(2)) {
return !this.optional(element);
}
return "dependency-mismatch";
}, $.validator.messages.required)
var v = $("#cmaForm").validate({
errorClass: "warning",
onkeyup: false,
onblur: false,
submitHandler: function() {
alert("Submitted, thanks!");
}
});
// back buttons do not need to run validation
$(".prevbutton").click(function(){
accordion.accordion("activate", 0);
current = 0;
});
$(".prevbutton").click(function(){
accordion.accordion("activate", 1);
current = 1;
});
// these buttons all run the validation, overridden by specific targets above
$(".open2").click(function() {
if (v.form()) {
accordion.accordion("activate", 2);
current = 2;
}
});
$(".open1").click(function() {
if (v.form()) {
accordion.accordion("activate", 1);
current = 1;
}
});
$(".open0").click(function() {
if (v.form()) {
accordion.accordion("activate", 0);
current = 0;
}
});
});
我對劇本的形式提交:(我不知道發生了什麼與表單的格式提交腳本,但它不應該像她那樣)
$(document).ready(function() {
var options = {
target: '#output2', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse, // post-submit callback
clearForm: true // clear all form fields after successful submit
};
$('#cmaForm').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
});
function showRequest(formData,jqForm,options)var queryString = $ .param(formData);
alert('About to submit: \n\n' + queryString);
return true;
}
功能showResponse方法(responseText的,狀態文本,XHR,$形式){
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
is ajaxSubmit a plugin? – jeschafe