最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to refresh page in php - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question edited Dec 31, 2013 at 14:11 Ahmed Siouani 13.9k12 gold badges63 silver badges73 bronze badges asked Dec 31, 2013 at 12:29 HungryDBHungryDB 5753 gold badges11 silver badges31 bronze badges 5
  • Header will not work in ajax call – Manish Jangir Commented Dec 31, 2013 at 12:31
  • try window.location.reload() – Thomas Commented Dec 31, 2013 at 12:31
  • You have to do this in JS, right after alert. window.location.reload() – Valdas Commented Dec 31, 2013 at 12:31
  • You can't do it with php! php is server side scripting language that can't interact with browser directly. Instead, you should use javascript – Givi Commented Dec 31, 2013 at 12:33
  • use window.location for redirection or window.reload for refresh. – user2727841 Commented Dec 31, 2013 at 12:37
Add a ment  | 

7 Answers 7

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

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!

use

 window.location.href = document.URL;

or

   window.location.reload(true);

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);
      });

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();
});

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!

发布评论

评论列表(0)

  1. 暂无评论