我已经使用core创建了我的登录表单,但是我有一个问题,就是我在ajax响应中得到了2 enter,这就是为什么我的条件不匹配,我的登录表单不能工作。
我的HTML:
<div id="block">
<form method="post" name="form">
<ul>
<li>Usename:</li>
<li><input id="email" type="text" name="un" size="25" required placeholder="Email" ></li>
</ul>
<ul>
<li>Password:</li>
<li><input id="password" type="password" name="up" size="25"></li>
<li><input type="button" name="submit" value="LOGIN" onClick="rr();"></li>
</ul>
</form>
</div>我的js:
function rr()
{
var data={
'un':$('#email').val(),
'up':$('#password').val()
}
$.ajax({
type:"POST",
data:data,
dataType:"text",
url:"/panchayat/web/action.php?action=login",
success:function(response)
{
if(response=='true')
{
window.location.assign("home.html");
}
else
{
alert("wrong credencials");
}
},
failure:function(response)
{
alert("there is an error.");
},
error:function(xhr, status, error)
{
alert("xhr.response");
}
});
}我的php:
function login()
{
$q=mysql_query("select * from tb_login");
$ft=mysql_fetch_array($q);
$_SESSION['emailid']=$_REQUEST["un"];
$_SESSION['pass']=$_REQUEST["up"];
if($_REQUEST["un"]==$ft["Emailid"] && $_REQUEST["up"]==$ft["Password"])
{
$n="true";
}
else
{
$n="WRONG USERNAME OR PASSWORD";
}
echo $n;
}有两个输入与‘真’来回应,使我的条件在成功的部分不match.please帮助我摆脱这些enters.thanx提前。
发布于 2013-08-29 12:32:30
您可以尝试使用response使用$.trim()删除这些空格。
if($.trim(response)=='true')https://stackoverflow.com/questions/18509472
复制相似问题