2011-02-23 48 views
-1

我想將(成功)後的表單重定向到另一個頁面。我使用此代碼ajax重定向問題

$(document).ready(function(){ 
$("#ajax-form").submit(function(){ 
    $.post(
     "ajaxContact/ajax-register.php", 
     $("#ajax-form").serialize(), 
     function(data){ 
      if (data.success) 
       $("span#ajax-message").css({'color':'green'}); 
       window.location("index.html"); 
      else 
       $("span#ajax-message").css({'color':'red'}); 
      $("span#ajax-message").html(data.message); 
     }, 
     "json" 
    ); 
    return false; 
}); 

});

如何重定向。

問候

回答

0
window.location = "http://www.google.com"; 
1

如果你只想重定向的頁面出現,這應該工作:

if(data.success) 
    window.location = "url"; 

更新時間:

$(document).ready(function() 
{ 
    $("#ajax-form").submit(function() 
    { 
      $.post("ajaxContact/ajax-register.php", $("#ajax-form").serialize(), 
      function(data) 
      { 
       if (data.success) 
       { 
        //If successful... 
        window.location = 'http://www.google.com'; 
       } 
       else 
       { 
        //If unsuccessful... 
        alert("Post was unsuccessful."); 
       }      
      },"json"); 

    return false; 
    }); 
}); 

這應該爲你工作作爲只要您的帖子成功返回即可。下面是一個使用確認模仿你的帖子演示:

Demo here

+0

沒有工作親愛 –

+0

還沒有看到它,因爲你更新你的代碼 - 我會再檢查一遍。 –