2014-01-23 175 views
0

後阿賈克斯成功函數之後刷新主網頁重定向頁面,我想重定向頁面,而無需刷新主頁怎麼沒有Ajax成功功能

$.ajax({ 
    type: "POST", 
    url: "save_edit.php", 
    data: { id1: id, comment1: comment }, 
    success: function(data) { 
     $("#feedback").html(data); 
     $('#feedback').fadeIn('slow', function() { 
      $('#feedback').fadeOut(4000); 
      window.location = "comment.php"; 
     } 
}); 
+0

調用另一個AJAX功能,你的'success'函數內部 – user2936213

+0

對不起,我是新來的jQuery的東西!你可以解釋嗎! – user3226210

+0

請參閱下面的答案。 – user2936213

回答

2
$.ajax ({ 
    type: "POST", 
    url: "save_edit.php", 
    data: { id1: id, comment1: comment }, 

    success: function(data) { 
      $("#feedback").html(data); 
      $('#feedback').fadeIn('slow', function() { 
      $('#feedback').fadeOut(4000); 
      $.ajax ({ 
       type: "POST", 
       url: "comment.php", 
       data: { }, 
      }); 
      } 
}); 
1

你不能重定向到一個頁面,而到comment.php令人耳目一新。您需要像這樣將頁面加載到當前頁面;

$.ajax ({ 
    type: "POST", 
    url: "save_edit.php", 
    data: { id1: id, comment1: comment }, 

    success: function(data) { 
      $("#feedback").html(data); 
      $('#feedback').fadeIn('slow', function() { 
      $('#feedback').fadeOut(4000); 
      $("body").load("comment.php"); 
    } 
}); 

comment.php應該只包含正文部分

-1

不知道你想要什麼,

但我認爲你要加載comment.php與實際重新加載頁面以及你可以改變

window.location = "comment.php"; 

$("html").load("comment.php"); // this will change the content of current page with comment.php content 
+0

謝謝Sanjeev ji,這對我有用。 – user3226210

+0

標記爲正確 – sanjeev

1

使用這樣的:

$.ajax ({ 
type: "POST", 
url: "save_edit.php", 
data: { id1: id, comment1: comment }, 

success: function(data) { 
     $("#feedback").html(data); 
     $('#feedback').fadeIn('slow', function() { 
     $('#feedback').fadeOut(4000); 
     $.ajax ({ 
      type: "POST", 
      url: "save_edit.php", 
     }); 
    } 
}); 
0

在成功事件使用

window.location.href="your page link";