我正在尝试servlet
通过将两种不同的javascript代码混合在一起来将我的html表单数据提交给a:
<script type="text/javascript">
$(document).ready(function() {
$("#form1").validate({
rules: {
name: "required",
email: {
required: true,
email: true
},
url: {
url: true
},
comment: {
required: true
}
},
messages: {
comment: "Please Enter Your Message."
},
submitHandler:function(login_form){
$(login_form).ajaxSubmit({
target: '#msg-box',
success: function() {
$('#form1').slideUp('slow', function(){
$(".show_hide").show();
});
}
});
}
});
});
</script>
第二个是(来自本教程):
<script type="text/javascript">
$(document).ready(function(){
$("#login_frm").submit(function(){
//remove previous class and add new "myinfo" class
$("#msgbox").removeClass().addClass('myinfo').text('Validating Your Login ').fadeIn(1000);
this.timer = setTimeout(function () {
$.ajax({
url: 'check.jsp',
data: 'un='+ $('#login_id').val() +'&pw=' + $('#password').val(),
type: 'post',
success: function(msg){
if(msg != 'ERROR') // Message Sent, check and redirect
{ // and direct to the success page
$("#msgbox").html('Login Verified, Logging in.....').addClass('myinfo').fadeTo(900,1,
function()
{
//redirect to secure page
document.location='login.jsp?user='+msg;
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Sorry, Wrong Combination Of Username And Password.').removeClass().addClass('myerror').fadeTo(900,1);
});
}
}
});
}, 200);
return false;
});
});
</script>
我不是 javascript 或 JQuery 忍者,任何人都请帮我将这些代码组合在一起。
有一件事是肯定我必须对submitHandler
代码进行很多更改,但我正在尝试但没有成功。
PS:任何关于 jsp-jquery-ajax 表单验证和提交的更好想法都非常欢迎