user3226210
user3226210

Reputation: 1

How redirect page without refreshing main page after ajax success function

After ajax success function, I want to redirect page to comment.php without refreshing main page

$.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";
        }
 });

Upvotes: 0

Views: 10430

Answers (4)

Systematix Infotech
Systematix Infotech

Reputation: 2365

On success event use

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

Upvotes: 0

user2936213
user2936213

Reputation: 1011

Use like this:

$.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",
      });
   }
});

Upvotes: 1

Hüseyin BABAL
Hüseyin BABAL

Reputation: 15550

You can not redirect to a page without refreshing. You need to load page into your current page like this;

$.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 should only contain body part

Upvotes: 1

Rohan
Rohan

Reputation: 3334

$.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: {  },
             });
            }
 });

Upvotes: 2

Related Questions