Sam
Sam

Reputation: 1381

refresh different page from current page

I have 2 separate pages, index and add_data. Initially, index page is open and this page has a link that opens add_data page in a different tab. Now add_data page has a form whose data is getting saved through ajax.if the ajax returns a success message, I wish to refresh the index page.

code on index page responsible for redirection

<a href="<?php echo base_url(); ?>class/add_data" target="_blank">Add Data</a>

Code of ajax on add_data page

jQuery.ajax(
          {
            type: "POST",
            url: "<?php echo base_url(); ?>" + "class/student/" ,
            data: formData,
            processData: false,
            contentType: false,
            success: function(res) 
              {
                console.log(res);
              },
          });

Can anyone please tell how this can be done

Upvotes: 1

Views: 1207

Answers (2)

Supun Praneeth
Supun Praneeth

Reputation: 3160

Try this:

index page

<a class="click" href="<?php echo base_url(); ?>class/add_data" target="_blank">Add Data</a>

<script>

 localStorage.setItem("return_suc", "0");
 $('body').on('click', '.click', function(){
    localStorage.setItem("return_suc", "1");
 });

window.setInterval(function(){
    if(localStorage["return_suc"] == "1"){
        location.reload();
    }
}, 500);

</script>

add_data page

jQuery.ajax(
      {
        type: "POST",
        url: "<?php echo base_url(); ?>" + "class/student/" ,
        data: formData,
        processData: false,
        contentType: false,
        success: function(res) {
             localStorage.setItem("return_suc", "1");
          }
      });

Upvotes: 1

Thomas Timbul
Thomas Timbul

Reputation: 1733

As per Reload parent window from child window you can use window.parent.location.reload(), assuming you have opened the add_data page using JavaScript window.open(...) from within the index page.

Upvotes: 0

Related Questions