Ajax 没有调用 servlet
我的 web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.web.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
</web-app>
剧本:
//function to check name and comment field
function checkCommentsForm(){
if(userName.attr("value") && userPass.attr("value"))
{
alert("true returned");
return true;
}
else
{
alert("fasle returned");
return false;
}
}
//When form submitted
$("#formL").submit(function(){
if(checkCommentsForm()){
$.ajax({
type:"POST",
url:"/LoginServlet/",
data:"user="+userName.val()+"&pass="+userPass.val(),
success: function(msg) {$('#targetDiv').hide();$("#targetDiv").html ("<h3>" + msg + "</h3>").fadeIn("slow");
}
});
alert('ppppppppppppppppp----------');
}
else
alert("Please fill UserName & Password!");
return false;
});
});
表格:
<div>
<form id="formL" name="formL" method="post" onsubmit="return false;">
<span class="style3"><strong>Enter Username &
Password to Login : </strong></span><br> <br> <span class="style1">Username : </span>
<input name="user" id="user" type="text"> <br>
<span class="style1">Password :</span> <input name="pass" id="pass" type="password"> <br>
<input name="button" id="button" value="Submit" type="submit">
</form>
</div>
<div id="targetDiv" style="display: none;"></div>
警报如下:
**The servlet are working but through ajax it was not called any clue what happen ?**