1

我一直在尝试通过 PHP 触发效果。基本上,当用户输入无效密码时,我想让提交按钮抖动。为此,我需要通过 PHP,并尝试在我的数据库中验证用户,如果失败,下面的代码应该会触发 jQuery 效果。

echo'<script>$(".shake").effect("shake", {times:2, distance:3, direction:"right"}, 45);</script>';

我知道为什么这可能不起作用,但我看不到另一种方法。

4

2 回答 2

1

为此,您需要 AJAX。客户端通过 AJAX 询问服务器密码是否正确,然后响应结果摇动按钮(或不摇动按钮)。像这样的东西:

$.ajax("http://www.example.com/ajax.php", {
  data: {
    username: username,
    password: password
  },
  success: function(data) {
    if (data.okay) {
      loggedIn = true;
    } else {
      $(".shake").effect("shake", {times:2, distance:3, direction:"right"}, 45);    if (data == "OK");
    }
  }
};

并在ajax.cgi

echo "Content-Type: application/json\n\n"
$username = $_GET("username");
$password = $_GET("password");
if (authenticate($username, $password)) {
  echo "{ \"okay\": true }";
}
于 2012-08-04T23:23:16.447 回答
0

为此,您需要使用 AJAX。

$('#submit').on('click', function() {
    $.ajax({
        url: "your/auth/script.php",
        type: "POST",
        success: function(result) {
            if(result !== 1) {
                $(".shake").effect("shake", {times:2, distance:3, direction:"right"}, 45);
            }
        }
    });
});
于 2012-08-04T23:25:28.327 回答