我发现了很多关于此的帖子,但我无法得到这个为我的生活工作。在提交表格时,我需要代码1)提交表格并2)重定向到案例陈述中的一个位置。我可以在没有案件的情况下提交表单,并且我可以让表单重定向,但是我无法将它们同时做到这一点。请告诉我我正处于正确的轨道上,但只是在错误的地方有代码,我一直盯着这个方式太长,并且遇到了障碍。Jquery提交表单,然后重定向不工作
$("#submitBtn").click(function (event) {
event.preventDefault();
var validator = $(this).closest("form").kendoValidator({
messages: {
required: function (input) { return getRequiredValidationMessage(input) },
custom: function (input) { return getInvalidValidationMessage(input) },
},
rules: {
custom: function (input) {
var minlength = $(input).attr('data-minlength');
var required = $(input).attr('required');
if (typeof minlength !== typeof undefined && minlength !== false && ((typeof required !== typeof undefined && required !== false) || $(input).val().length > 0)) {
var minlength = $(input).data('minlength');
return $(input).val().length >= minlength;
} else {
return true;
}
}
}
}).data("kendoValidator");
if (validator !== undefined) {
if (validator.validate()) {
$("aspnetForm").submit();
if ($("aspnetForm").submit()){
switch(document.getElementById('interests').value){
case "stair-lifts":
window.location.href="/Catalog/Online-Catalog-Category/15522/Stair-Lifts";
break;
case "wheelchair-ramps":
window.location.href="/Catalog/Online-Catalog-Category/15521/Ramps";
break;
case "roll-in-barrier-free-showers":
window.location.href="/Catalog/Online-Catalog-Category/15529/Bathroom-Safety";
break;
case "walk-in-tubs":
window.location.href="/Catalog/Online-Catalog-Category/15529/Bathroom-Safety";
break;
case "patient-lifts-ceiling-lifts":
window.location.href="/Catalog/Online-Catalog-Category/15523/Patient-Lift";
break;
case "wheelchair-lifts":
window.location.href="/Catalog/Online-Catalog-Category/15525/Wheelchair--Scooter-Lifts";
break;
default:
window.location.href="/"; // if no selection matches then redirected to home page
break;
}// end of switch
}
} else {
$('.k-invalid:first').focus();
$('.k-invalid').blur(function() { if (this.checkValidity()) { $('.k-invalid:first').focus(); } });
}
} else {
$(this).closest("form").submit();
}
});
});
嗯,似乎没有与.NET工作,我想唯一的方法来做到这一点是创建一个隐藏的字段,存储的价值,然后重定向提交。 – jlg
你可以更新你的帖子以显示你目前使用的是什么?我不认为将任何内容存储在隐藏字段中都会起作用,因为当您执行'.submit()'时,会导致整个页面重新加载。任何隐藏的字段最终都会随着页面的其余部分一起被丢弃。 –