我有一个 ajax 调用,如下所示:
$("#loginForm").submit(function(e){
$.ajax({
type:'POST',
url:'login.php',
data: $("#loginForm").serialize();
success: function(data){
if(data=="1"){
$("#message").html('<span class="gmessage">You are already logged in!</span>');
}
else if(data=="2"){
$("#message").html('<span class="gmessage">You have been logged in!</span><br/>'
'<span class="bmessage">You will be redirected in 10 seconds</span>');
$("#message").fadeOut(1000, function(){
window.location = <?php echo $_SESSION['ref'];?>;
});
}
else if(data=="3"){
$("#message").html('<span class="rmessage">The password you entered was incorrect</span>');
}
else if(data=="4"){
$("#message").html('<span class="rmessage">That account does not exist, you may need to register for an account</span>');
}
else{
$("#message").html('<span class="rmessage">There was an error: please try again</span>');
}
}
});
e.preventDefault();
});
php 已经过测试,并且根据跨度中的消息按预期运行,但是当执行此 ajax 调用时,不会显示任何消息,那就是它是否正在执行。对应的html是这样的:
<tr>
<td id="message" name="message" colspan="2"></td>
</tr>
<tr>
<td colspan="2" style="height:50px">
<center>
<input type="submit" name="submit" id="submit" value="Login!" style="font-family: arial;font-size:14pt;"/><br/><br/>
<span class="registerSpan">Don't have an account?:</span><br/><br/>
<input type="button" onClick="parent.location='createacct.php'" style="font-family:arial; font-size:14pt;" value="Register"/>
</center>
</td>
</tr>
为什么这不起作用?另一个相关问题:ajax 是处理这个问题的最佳方式吗?