好吧,这是一个使用ajax导航加载页面加载罚款其自我我试图使它,以便页面提交时,它不会刷新整个页面。我环顾了一会儿,仍然找不到修复它。表单提交停止刷新
<head>
<script>
$(document).on('submit', '#changePassword', function() {
$("#content").load("core.home");
return false;
});
</script>
</head>
<?php if(!preg_match("/index.php/i", $_SERVER[ 'PHP_SELF'])) { die(); } ?>
<form action="" method="post" id="changePassword">
<div class="box">
<div class="boxhead purple purple">
<strong>Change password</strong>
</div>
<?php if($_POST[ 'submit']) { try { $oldpassword=$ core->clean($_POST['current_password']); $oldpassword_enc = $core->encrypt($oldpassword); $newpassword = $core->clean($_POST['new_password']); $newpassword_enc = $core->encrypt($newpassword); if(!$oldpassword or !$newpassword) { throw new Exception(
"All fields are required."); } elseif($oldpassword_enc != $user->data['password']) { throw new Exception("The password you entered does not match the one we have on record."); } else { $db->query("UPDATE users SET password = '{$newpassword_enc}'
WHERE id = '{$user->data['id']}'"); echo "
<div class=\ "square good\">"; echo "<strong>Success</strong>"; echo "
<br />"; echo "Password successfully changed!"; echo "</div>"; $db->query("INSERT INTO logs VALUES (NULL, 'Changed Password <font color=\ "51c833\"><b>Success</b></font>', NULL, '<b>{$user->data['fullUsername']}</b> ({$_SERVER['REMOTE_ADDR']})', '3') "
); } } catch(Exception $e) { echo "
<div class=\ "square bad\">"; echo "<strong>Error</strong>"; echo "
<br />"; echo $e->getMessage(); echo "</div>"; $db->query("INSERT INTO logs VALUES (NULL, 'Changed Password <font color=\ "FF0000\"><b>Fail</b></font> Reason: {$e->getMessage()}', NULL, '<b>{$user->data['fullUsername']}</b> ({$_SERVER['REMOTE_ADDR']})',
'3') "); } } ?>
<table width="100%" cellpadding="3" cellspacing="0">
<?php echo $core->buildField("password", "required", "current_password", "Current password"); echo $core->buildField("password", "required", "new_password", "New password"); ?>
</table>
</div>
<div class="box" align="right">
<button class="button" type="submit" name="submit" value="Submit" id="button">Submit</button>
</div>
</form>
<?php echo $core->buildFormJS('changePassword'); ?>
你想做什么实际?详细解释它。 – Archish
这里的代码是一个单独的文件,当它被提交表单时,它被加载到一个ajax框中,它刷新整个网站回index.php我不想要一个网站全面刷新发生 –