Is it possible to redirect the page with PHP after an Ajax call?

后端 未结 4 773
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 03:57

I have a website where I want to provide an option for users, if they click on a table\'s rows, they get regirected to another page (based on the contect of the table row).

4条回答
  •  轮回少年
    2021-01-29 04:30

    Yes and no. If you work with jquery, and your ajax call responds with a json like this:

    {
        success : true, 
        redirect_to : "http://www.google.com"
    }
    

    that in php means

     true,
        'redirect_to' => 'http://www.google.com',
    ]);
    

    then your ajax caller can do the dirty job:

    $.get('/your/path', function (json) {
        if(json.success) {
            document.location.href = json.redirect_to;
        }
    }, 'json');
    

    My two cents.

提交回复
热议问题