1

我遇到了 die() 命令的问题。我的网站上有一个会员注册页面,其操作是另一个 php 脚本。提交后,页面将重定向到我的 temp_handle.php,而不是带有正确错误的警报,并回显错误命令。此外,success 方法不会重定向页面。我正在构建上一页的新版本,并且我已经选择了以前作者的代码,所以我知道这种方法有些工作。我正在用引导程序重新设计它。

...
<form class="form-horizontal" action="2/temp_handle.php" id="registerForm" method="post">
    <input type="text" name="first_name">
</form>
...

这个表单被提交给 temp_handle.php,它执行:

$first_name = sanitize($_POST['first_name']);
if (!$first_name || (strlen($first_name) > 32)) 
    die('error: first_name');

回到注册页面,

$(document).ready(function () {
    $('#registerForm').ajaxForm(function (response) {
        if (response == 'success') {
            alert('Thank you, your registration has been processed.');
            window.location.replace('myURL'); //actual URL in real code
            //TODO redirect to success page
        } else {
            alert('Registration failed, ' + response);
        }
    });
});

相反,页面打印

错误:名字

任何帮助表示赞赏。谢谢!

4

1 回答 1

2

看起来您的表单是以“正常”/非 ajax 方式提交的,这意味着 javascript 存在问题:

  1. 未加载 jQuery;
  2. 表单插件未加载;
  3. 您的 javascript 中有错误(我在您发布的内容中看不到任何错误)。
于 2013-06-10T19:51:29.633 回答