开发者

from javascript call a jsp page

I am new to stackoverflow i have doubt regarding calling jsp from javascript file. my file contain one html file with jav开发者_运维知识库ascript(home.html) and one jsp file(login.jsp) In html(home.html) file i have 2 textbox and 2 buttons one for login and another for reset.when i click the login button i should call a js for textbox field validation (ie for if any one of the textbox is empty it shows "text fields should not be empty" alert msg to user)if both the textbox have value then it should call a jsp page(login.jsp).Thanks in advance


<form id="myform" action="login.jsp" method="post">
<input name="u" id="u"> Username<br>
<input name="p" id="p" type="password"> Password
</form>
<script>
document.getElementById('myform').addEventListener('submit', function(e) {
if (!document.getElementById('u').value || !document.getElementById('p').value)
e.preventDefault();
}, false);
</script>


<script language="JavaScript">
function val(){
    var name=...
    var pass=...
    if(name==" "||pass==" ")
    {
    alert("fields should not be empty");
    }
    else{
    var jspcall = "login.jsp?param1=value1&param2=value2";
    window.location.href = jspcall;
    }
}
    </script>


Try using jquery

$.post("login.jsp", { name: "John", time: "2pm" },
   function(data){
     alert("Data Loaded: " + data);
});

ref: http://api.jquery.com/jQuery.post/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜