我正在使用这个jQuery Validation脚本来提交我的表单,但我需要一些帮助来调整它以显示消息,并再次显示表单(提交后)
http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
^^代码
http://www.position-relative.net/creation/formValidator/demoSubmit.html
^^演示
如果您查看演示,我希望它显示绿色消息并再次显示表单(而不是隐藏它)..我似乎无法弄清楚脚本中的哪个位置可以更改它。这是执行ajax提交功能的JS代码的片段:
submitForm: function (caller) {
if ($.validationEngine.settings.ajaxSubmit) {
$.ajax({
type: "POST",
url: $.validationEngine.settings.ajaxSubmitFile,
async: true,
data: $(caller).serialize(),
beforeSend: function () {
},
success: function (data) {
if (data == "true") { // EVERYTING IS FINE, SHOW SUCCESS MESSAGE
$(caller).css("opacity", 1)
$(caller).animate({
opacity: 0,
height: 0
},
function () {
$(caller).css("display", "none")
$(caller).before("<div class='ajaxSubmit'>" + $.validationEngine.settings.ajaxSubmitMessage + "</div>")
$.validationEngine.closePrompt(".formError", true)
$(".ajaxSubmit").show("slow")
if ($.validationEngine.settings.success) { // AJAX SUCCESS, STOP THE LOCATION UPDATE
$.validationEngine.settings.success && $.validationEngine.settings.success();
return false;
}
})
} else { // HOUSTON WE GOT A PROBLEM (SOMETING IS NOT VALIDATING)
data = eval("(" + data + ")");
errorNumber = data.jsonValidateReturn.length
for (index = 0; index < errorNumber; index++) {
fieldId = data.jsonValidateReturn[index][0];
promptError = data.jsonValidateReturn[index][1];
type = data.jsonValidateReturn[index][2];
$.validationEngine.buildPrompt(fieldId, promptError, type);
}
}
}
})
return true;
}
if ($.validationEngine.settings.success) { // AJAX SUCCESS, STOP THE LOCATION UPDATE
$.validationEngine.settings.success && $.validationEngine.settings.success();
return true;
}
return false;
},
答案 0 :(得分:1)
更新的if语句可能类似于:
if (data == "true") { // EVERYTING IS FINE, SHOW SUCCESS MESSAGE
$(caller).before("<div class='ajaxSubmit'>" + $.validationEngine.settings.ajaxSubmitMessage + "</div>")
$.validationEngine.closePrompt(".formError", true)
$(".ajaxSubmit").show("slow")
if ($.validationEngine.settings.success) { // AJAX SUCCESS, STOP THE LOCATION UPDATE
$.validationEngine.settings.success && $.validationEngine.settings.success();
return false;
}
}