Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.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
Php $.ajax调用上的强制重定向页面_Php_Jquery_Ajax_Codeigniter - Fatal编程技术网

Php $.ajax调用上的强制重定向页面

Php $.ajax调用上的强制重定向页面,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,假设我有以下ajax调用: $.ajax({ type: 'POST', url: 'some_url', dataType: 'json', data: { some: data }, success: function(data){ // Success message will be shown. window.setTimeout(function(){location.reload()}, 2000); }

假设我有以下ajax调用:

$.ajax({
    type: 'POST',
    url: 'some_url',
    dataType: 'json',
    data: { some: data },
    success: function(data){
        // Success message will be shown.
        window.setTimeout(function(){location.reload()}, 2000);
    },
    failed : function(data){
        // Error message will be shown.
        window.setTimeout(function(){location.reload()}, 2000);
    }
});
在服务器端,我有如下内容:

function delete_json(){
    $post = $this->input->post();
    if(!empty($post)){
        // Do something crazy here and return the result as JSON.

        header('Content-Type: application/json');
        echo json_encode($data);
        exit;
    }else{
        // CURRENTLY THIS DOES NOT WORK......
        // IT DOES NOT REDIRECT THE PAGE AS INTENDED
        redirect('some_url', 'refresh');
    }
}
如果ajax调用仍然希望返回结果,如何强制将用户重定向到另一个页面


有什么好方法可以做到这一点呢?

因为这是一个AJAX调用,不会对浏览器产生明显的影响。您必须在客户端执行重定向

$.ajax({
    type: 'POST',
    url: 'some_url',
    dataType: 'json',
    data: { some: data },
    success: function(data){
        // Success message will be shown.
        if(data.good===true){
          window.setTimeout(function(){location.reload()}, 2000);
        }
        else{
          window.location.href("http://my.url.here");
        }

    },
    failed : function(data){
        // Error message will be shown.
        window.setTimeout(function(){location.reload()}, 2000);
    }
});

异步中的ajax调用通过json返回重定向url,在ajax成功中重定向您需要在AjaxThank@Alex的成功函数中重定向,这就是我的想法。我想我需要从客户端进行重定向。