一个空行,执行结果截然不同?
附件上传不了,只有粘贴了:jsp+jquery+ajax的一个简单的实例,其中login.jsp首行为空行时,结果就错误了,实在不可思议??
login.htm
<html>
<head>
<script src="js/jquery.js" type="text/javascript"> </script>
<script src="js/login.js" type="text/javascript"> </script>
<script src="lib/jquery.tablesorter.js" type="text/javascript"> </script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
body { font:12px/1.6em "宋体" }
ul { list-style:none; }
li { margin-top:10px; }
</style>
</head>
<body>
<h3>会员登录 </h3>
<div id="login">
<form method="post" action="login.asp" id="form2">
<div id="confirm"> </div>
<ul>
<a href = "#">aa </a>
<li>名字: <input type="text" id="user" size="16" maxlength="20"></li>
<li>密码: <input type="password" id="pass" size="16" maxlength="20"></li>
<li>
<input type="submit" style="border:0" />
</li>
</ul>
</form>
</div>
</body> </html>
login.js
$(document).ready
(
function()
{
$("#form2").submit
(
function()
{
login();
return false;
}
);
}
);
function login()
{
var user = $("#user").val();
var pass = $("#pass").val();
if (user == "")
{
$("#confirm").html("请输入登录用户名");
$("#user").focus();
return false;
}
if(pass == "")
{
$("#confirm").html("请输入登录密码");
$("#pass").focus();
return false;
}
$.ajax({
type: "POST",
url: "login.jsp",
data: "user=" + user + "&psw=" + pass,
beforeSend: function(){
$("#confirm").html("登录中,请稍候......");
},
success: function(msg){
alert(msg);
if(msg == "success"){
$("#confirm").html("登录成功,欢迎" + user + "回来!正在进入你的空间......");
// window.location.href("success.htm");
// document.location.href = "success.htm";
}else {
$("#confirm").html("没有此用户或者密码不正确!");
}
// $("#confirm").html(msg);
}
});
}
login.jsp
<%
String id = (String)request.getParameter("user");
String p = (String)request.getParameter("psw");
//out.print(id+' ' +p);
if( (id!=null && id.equals("admin")) && (p!=null && p.equals("admin")) )
{
out.print("success");
}
else
{
out.print("failed");
}
%>