-1

i'm using ajax call on the php page(my.php) to pass JS variables and JS array to another php page(destiny.php). Now in destiny.php i do some DB operations.

$.ajax({        
    type: "POST",
    url: "destiny.php",
    data: { b_Array : b_arr, b_value : b_val},
    success: function(data) {
        window.alert(data);
    }

But sometimes due to user inputted error (through Js variables or Js array), i have to show an alert (right now using above code window.alert(data) to show alert) But it doesn't refresh the page.

how can i refresh the page then? i tried header(). but still it doesn't work.

Ahmed Siouani
  • 13,701
  • 12
  • 61
  • 72
HungryDB
  • 555
  • 3
  • 11
  • 30

7 Answers7

2

Try window.location

$.ajax({        
    type: "POST",
    url: "destiny.php",
    data: { b_Array : b_arr, b_value : b_val},
    success: function(data) {
        window.location = "your_url";
    });
Ahmed Siouani
  • 13,701
  • 12
  • 61
  • 72
웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
2
$.ajax(
  {        
    type: "POST",
    url: "destiny.php",
    data: { b_Array : b_arr, 
        b_value : b_val},
    success: function(data) {
      **window.location.reload();**
  }

but i think refreshing is not a good idea

miki
  • 21
  • 1
2
window.location.reload(true);

This is the best way to reach what you want, although you also may check out this code bellow:

function auto_reload()
{

  var timer = window.location.reload();

   for (var i=0;i<timer.length;i++){

    setTimeout(timer, 1000);

    timer = false;


      }
}

I hope it helps!

Thiago Lima
  • 21
  • 1
  • 4
1

use

 window.location.href = document.URL;

or

   window.location.reload(true);
Manish Jangir
  • 5,329
  • 4
  • 42
  • 75
1

Use

window.location.reload(true);

itwill perform a refresh.

$.ajax(
      {        
        type: "POST",
        url: "destiny.php",
        data: { b_Array : b_arr, 
            b_value : b_val},
        success: function(data) {
        window.location.reload(true);
      });
Moyed Ansari
  • 8,436
  • 2
  • 36
  • 57
1

Use location.reload(); Js Function

$.ajax({        
        type: "POST",
        url: "destiny.php",
        data: { b_Array : b_arr, 
            b_value : b_val},
        success: function(data) {
        alert(data);
        location.reload();
});
Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53
0

Try this:

User either of this two option.

window.location.href = document.URL; 
OR
window.location.reload(true);

Write this at last in ajax response.

Thanks!

Anand Solanki
  • 3,419
  • 4
  • 16
  • 27