我有一个使用Jquery验证客户端的表单.然后,Jquery将此数据传递给php脚本以进行服务器端验证.在PHP脚本的最后,我尝试重定向成功,但没有重新指向发生.
Jquery是否干扰了重定向?如何让php脚本重定向?不想使用jquery重定向,bc我将使用会话并希望将会话数据保留在重定向.
这是代码:
JQUERY:
$.ajax({
//this is the php file that processes the data and send mail
url: "includes/process/processAdminLogin.php",
//POST method is used
type: "POST",
//pass the data
data: dataString,
//indicate result is text
dataType: "text",
//Do not cache the page
cache: false,
//success
success: function (data) {
$('input').removeAttr('disabled'); //enable input fields again.
if(data == "fail"){
$("#statusMessage").html("");
$("#statusMessage").html("<p class='statusBoxWarning'>Username and password do not match!</p>");
$('button').removeAttr('disabled');
document.forms[0].reset();
}
}
});
Run Code Online (Sandbox Code Playgroud)
PHP
if($correctPass == 1){
ob_start();
session_start();
$_SESSION['usernameIdentity'] = …Run Code Online (Sandbox Code Playgroud) 我有2个链接,隐藏主页上的用户不同的信息.如果单击一个链接,则新信息将显示在屏幕上.问题是,当我点击任何链接时,窗口将被带回页面顶部.我想防止这种行为,因为它很烦人.
这是链接的代码
<div align="right" id="ajaxIncomingMail"><a href="#" class="incomingMail">Incoming Mail</a></div><div id="ajaxOutgoingMail"><h5><a href="#" class="outgoingMail">Outgoing Mail</a></h5></div>
Run Code Online (Sandbox Code Playgroud)
这是jquery的代码:
$(function(){
$("a.incomingMail").click(function(e){
e.preventDefault();
$("#ajaxMailShowContentOutbox").hide();
$("#ajaxMailShowContentInbox").fadeIn("slow");
});
$("a.outgoingMail").click(function(e){
e.preventDefault();
$("#ajaxMailShowContentInbox").hide();
$("#ajaxMailShowContentOutbox").fadeIn("slow");
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
在这里,我使用的是preventDefault(),它仍然无法正常工作!?我也尝试过返回false,但这也不起作用.我不知道它是否重要,但所提供的信息是从数据库中提取的.点击链接后如何才能使滚动停止?