如何调用设置超时功能

时间:2015-12-28 08:40:27

标签: jquery

使用设置超时功能如何将页面重定向到我的管理主页我试图通过使用jquery提交表单。

在php中我使用标题位置管理索引php页面但是如何在这个jquery表单中重定向它可以帮助我使用这段代码。

 <form method="POST" class="login" action="">
    <p class="title">Log in</p>
    <input type="text" name="username" id="username" placeholder="Username" autofocus/>
    <i class="fa fa-user"></i>
    <input type="password" name="password" id="password" placeholder="Password" />
    <i class="fa fa-key"></i>
    <a href="forgotpassword.php">Forgot your password?</a>
    <button>
      <i class="spinner"></i>
      <span class="state"><input type="submit" name="Submit" value="Log in"></span>
    </button>
  </form>

var working = false;
$('.login').on('submit', function(e) {
  e.preventDefault();
  if (working) return;
  working = true;
  var $this = $(this),
    $state = $this.find('button > .state');
  $this.addClass('loading');
  $state.html('Authenticating');
  setTimeout(function() {
    $this.addClass('ok');
    $state.html('Welcome back!');
    setTimeout(function() {
      $state.html('Log in');
      $this.removeClass('ok loading');
      working = false;
    }, 4000);
  }, 3000);
});

2 个答案:

答案 0 :(得分:0)

要重定向到管理页面,您可以使用window.location.href =&#39; adminpage.php&#39;

<div id="footer">

请了解Ajax,我认为您不了解流程。

答案 1 :(得分:0)

更改此代码:

setTimeout(function() {
      $state.html('Log in');
      $this.removeClass('ok loading');
      working = false;
    }, 4000);

到这一个:

setTimeout(function() {
      $state.html('Log in');
      $this.removeClass('ok loading');
      working = false;
      window.href.location = 'adminpage.php';
    }, 4000);