使用jquery重定向到servlet类文件

使用jquery重定向到servlet类文件,jquery,servlets,redirect,Jquery,Servlets,Redirect,我使用了jquery-1.11.2.min.js和chrome 40.0.2214.115 在用户注册表单中,如果任何字段为空,我希望向用户显示警报消息,否则重定向到servlet类文件,在该servlet类中,我编写了用于插入用户详细信息的db连接 我的用户注册html代码是 <script type="text/javascript" src="js/plugins/jquery-1.11.2.min.js"></script> <script>

我使用了jquery-1.11.2.min.js和chrome 40.0.2214.115

在用户注册表单中,如果任何字段为空,我希望向用户显示警报消息,否则重定向到servlet类文件,在该servlet类中,我编写了用于插入用户详细信息的db连接

我的用户注册html代码是

    <script type="text/javascript" src="js/plugins/jquery-1.11.2.min.js"></script>
<script>
$(document).ready(function()
        {
    $("#submitid").click(function()
      {
        var fname=$("#firstname2").val();
        var lanme=$("#lastname2").val();
        var email=$("#email2").val();
        var mobileno=$("#mobileno").val();
        var username=$("#username").val();
        var pass=$("#password").val();
        if(fname==''||lname==''||email=''||mobileno==''||username==''||pass=='')
            {
            alert("Enter all fields");
            $("#userform").focus();

            }
        else
            window.location.href("Userdetailsins.java");
            });
        });</script>
</head>

<body>

<form class="stdform stdform2" method="post"  id="userform">
<label>First Name</label>
 <input type="text" name="userfname" id="firstname2" class="longinput" />
<label>Last Name</label>
<input type="text" name="userlname" id="lastname2" class="longinput" />
<label>Email</label>
<input type="text" name="mailid" id="email2" class="longinput" 
<label>Mobile no</label>
 <input type="text" name="mobno" id="mobileno" class="longinput" 
 <label>User name </label>
 <input type="text" name="username" id="username" class="longinput" />
 <label>User Password </label>
 <input type="password" name="password" id="password" class="longinput" /></span>                     
 <input type="reset" value="Reset Button" />
 <input type="submit"  id="submitid" name="submitid" value="Next"/>
  </form>
</body>
</html>
open()方法可以工作,但我不想作为单独的窗口打开,我只是想重定向。请任何人帮助解决这个问题

谢谢……

用这个

function nextredirect(){
  window.location.href = 'next.html';
}
Jquery

$('#submitid').click(function(){

if($('#firstname2').val() == ""){
alert('Please enter the first name');
}else{
 window.location.href = 'next.html';
}
});
Html



使用此u获取任何错误窗口。location.href(“next.html”)@AshaThanks@coding我没有犯任何错误。位于同一页面上的表单没有重定向到next.html。单击后,您需要重定向到另一页面,对吗?请尝试我的答案asha,它可以工作:)感谢它在onclick事件中工作。但是我想使用jquery验证表单,然后我将重定向到下一页。。。在jquery中有什么方法吗@编码破解很高兴帮助您:)@Ashaone more request Coding cracker当使用输入类型作为按钮时,您的代码可以工作,但输入类型=“submit”表单不会重定向。请帮助解决这个问题@编码cracker$(“#这里是您的提交按钮id”).submit(函数(e){return false;});否则你可以$('#formid')。提交而不是
window.location.href='next.html'
这个Asha收到了吗?
$('#submitid').click(function(){

if($('#firstname2').val() == ""){
alert('Please enter the first name');
}else{
 window.location.href = 'next.html';
}
});
 <input type="button"  id="submitid" name="submitid" value="Next" onclick="nextredirect()"/>