发送表单后如何重定向到 JS / jQuery 中的另一个页面?

How do I redirect to another page in JS / jQuery after sending a form?

我正在尝试制作一个可在同一表单页面上运行的 JS 脚本。一切正常,直到成功登录后重定向。

$(document).ready(function() {
  $('#loginForm').submit(function(e) {
    e.preventDefault();

    $.ajax({
      url: 'goLogin.php',
      type: 'POST',
      data: $(this).serialize(),
      dataType: 'html'
    }).done(function(data) {
      $('#results').fadeOut('slow', function() {
        $('#results').fadeIn('slow').html(data);
        window.setTimeout(function() {
          window.location.href = 'index.php';
        }, 5000);
      });
    }).fail(function() {
      alert('Error!');
    });
  });
});
$.ajax({
      url: 'goLogin.php',
      type: 'POST',
      data: $(this).serialize(),
      dataType: 'html',
      success: function(data){
    $('#results').fadeOut('slow', function() {
        $('#results').fadeIn('slow').html(data);
        window.setTimeout(function() {
          window.location.href = 'index.php';
        }, 5000);
      });
    },
    error: function(data){
     alert('Error!');
}
}); 

请检查此代码...替换您的 ajax 部分...