หน้า 1 จากทั้งหมด 1

ติดปัญหา redirect หน้าไม่ไปจากไฟล์ php

โพสต์แล้ว: 23/09/2015 7:32 pm
โดย thatsawan

โค้ด: เลือกทั้งหมด

<form action="{AJAX_URL}" method="POST" id="fbpost" data-ajax="register_ajax">
        <input id="name" name="name" type="hidden" />
        <input  id="email" name="email" type="hidden" />
</form>
ไฟล์ php ที่รับค่ามา check

โค้ด: เลือกทั้งหมด

 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
                         exit();
เเล้วต้องการให้มันเปลี่ยนหน้า มันไม่ทำงาน
Selection_119.png
Selection_119.png (46.29 KiB) Viewed 2267 times

-----------------------------------------
อีกวิธีที่อยากให้มันทำงาน ส่ง json ออกมาเเล้วใช้ jquery เปลี่ยนหน้าเเทน

โค้ด: เลือกทั้งหมด

$json_response = new \phpbb\json_response;
                        $json_response->send(array(
                            'redirect' => TRUE,
                        ));

โค้ด: เลือกทั้งหมด

 (function ($) {
//
                "use strict";

                phpbb.addAjaxCallback('register_ajax', function (data) {
                        //    console.log(data);
                        if (data.redirect == true) {
                                window.location.href = "{REDIRECT}";

                        }
                        if(data.login_register == true){
                                window.location.href = "{LOGIN_REGISTER}";
                        }

                });
        })(jQuery);

Re: ติดปัญหา redirect หน้าไม่ไปจากไฟล์ php

โพสต์แล้ว: 26/09/2015 2:00 pm
โดย thatsawan
วิธีที่จะทำให้ redirect จากไฟล์ php ที่ทำงาน Ajax ต้องใช้

โค้ด: เลือกทั้งหมด

meta_refresh(3, append_sid("{$this->root_path}index.$this->php_ext"));    
 trigger_error($data[$value]); 
จำเป็นต้องมี trigger_error ด้วยค่ะ ไม่งั้นมันจะ redirect เเค่ส่วนการทำงานของ ajax มันจะไม่เปลี่ยนหน้าให้

Re: ติดปัญหา redirect หน้าไม่ไปจากไฟล์ php

โพสต์แล้ว: 26/09/2015 2:09 pm
โดย thatsawan
อีกวิธี phpbb_alert

โค้ด: เลือกทั้งหมด

 $url = 'https://www.mindphp.com/forums';
                $json_response = new \phpbb\json_response;
                $json_response->send(array(
                    //'user_id' => $user_id,
                    //'username' => $username,
                    'ESSAGE_BODY'        => $this->template->assign_display('show_all.html'),//$this->template->assign_display('body'),
                    'MESSAGE_TITLE' => '<div class="title_show_all">'.$this->user->lang['USER_ALL_LIKE'].'</div>',
                    'MESSAGE_TEXT' => $user_show_all,
                    'REFRESH_DATA'    => array(
                                   'time'    => 3,
                                   'url'        => $url,
                 )
                )); 

โค้ด: เลือกทั้งหมด

    'REFRESH_DATA'    => array(
                                                'time'    => 3,
                                                'url'        => $url,
                                        ) 

Re: ติดปัญหา redirect หน้าไม่ไปจากไฟล์ php

โพสต์แล้ว: 27/09/2015 8:22 pm
โดย thatsawan
สิ่งสำคัญที่ทำให้พลาดกันได้ data-refresh="true" ถ้าไม่ใส่ จะไม่สามารถ redirect ได้ ค่ะ (พลาดรอบ 2 ^^)

โค้ด: เลือกทั้งหมด

<a href="/link.php?id=4" data-ajax="true" data-refresh="true">link</a> 
thatsawan เขียน:meta_refresh(3, append_sid("{$this->root_path}index.$this->php_ext"));
trigger_error($data[$value]);
thatsawan เขียน:อีกวิธี phpbb_alert

โค้ด: เลือกทั้งหมด

 $url = 'https://www.mindphp.com/forums';
                $json_response = new \phpbb\json_response;
                $json_response->send(array(
                    //'user_id' => $user_id,
                    //'username' => $username,
                    'ESSAGE_BODY'        => $this->template->assign_display('show_all.html'),//$this->template->assign_display('body'),
                    'MESSAGE_TITLE' => '<div class="title_show_all">'.$this->user->lang['USER_ALL_LIKE'].'</div>',
                    'MESSAGE_TEXT' => $user_show_all,
                    'REFRESH_DATA'    => array(
                                   'time'    => 3,
                                   'url'        => $url,
                 )
                ));

โค้ด: เลือกทั้งหมด

    'REFRESH_DATA'    => array(
                                                'time'    => 3,
                                                'url'        => $url,
                                        )