簡體   English   中英

發送表單后,如何重定向到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部分...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM