Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在php中刷新页面_Javascript_Php_Ajax - Fatal编程技术网

Javascript 如何在php中刷新页面

Javascript 如何在php中刷新页面,javascript,php,ajax,Javascript,Php,Ajax,我在php页面(my.php)上使用ajax调用将JS变量和JS数组传递到另一个php页面(destiny.php)。现在在destiny.php中,我执行一些DB操作 $.ajax({ type: "POST", url: "destiny.php", data: { b_Array : b_arr, b_value : b_val}, success: function(data) { window.alert(data);

我在php页面(my.php)上使用ajax调用将JS变量和JS数组传递到另一个php页面(destiny.php)。现在在destiny.php中,我执行一些DB操作

$.ajax({        
    type: "POST",
    url: "destiny.php",
    data: { b_Array : b_arr, b_value : b_val},
    success: function(data) {
        window.alert(data);
    }
但有时由于用户输入的错误(通过Js变量或Js数组),我必须显示警报(现在使用上面的代码
window.alert(data)
来显示警报),但它不会刷新页面

那我怎么刷新页面呢?我尝试了header()。但它仍然不起作用。

试试看

使用

使用

它将执行刷新

$.ajax(
      {        
        type: "POST",
        url: "destiny.php",
        data: { b_Array : b_arr, 
            b_value : b_val},
        success: function(data) {
        window.location.reload(true);
      });
使用;Js函数

$.ajax({        
        type: "POST",
        url: "destiny.php",
        data: { b_Array : b_arr, 
            b_value : b_val},
        success: function(data) {
        alert(data);
        location.reload();
});
但我认为提神不是一个好主意

window.location.reload(true);
这是达到您想要的目的的最佳方式,尽管您也可以查看下面的代码:

function auto_reload()
{

  var timer = window.location.reload();

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

    setTimeout(timer, 1000);

    timer = false;


      }
}
功能自动重新加载()
{
var timer=window.location.reload();
对于(var i=0;i尝试以下方法:

User either of this two option.

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

Write this at last in ajax response.

谢谢!

Header在ajax calltry window.location.reload()中不起作用。您必须在JS中,在alert.window.location.reload()之后立即执行此操作。php不能使用php!php是服务器端脚本语言,不能直接与浏览器交互。相反,您应该使用window.location进行重定向或使用window.reload进行刷新。
$.ajax({        
        type: "POST",
        url: "destiny.php",
        data: { b_Array : b_arr, 
            b_value : b_val},
        success: function(data) {
        alert(data);
        location.reload();
});
$.ajax(
  {        
    type: "POST",
    url: "destiny.php",
    data: { b_Array : b_arr, 
        b_value : b_val},
    success: function(data) {
      **window.location.reload();**
  }
window.location.reload(true);
function auto_reload()
{

  var timer = window.location.reload();

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

    setTimeout(timer, 1000);

    timer = false;


      }
}
User either of this two option.

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

Write this at last in ajax response.