Hướng dẫn call javascript function from controller in codeigniter - gọi hàm javascript từ controller trong codeigniter

Họ không thể đưa mã JavaScript vào bộ điều khiển.

Phương pháp khả thi

Phương pháp một:

Tạo một chế độ xem lỗi và khi nào bạn muốn hiển thị một số lỗi chuyển hướng người dùng đến trang đó.

Phương pháp hai:

public function login_form() {


    $CI = & get_instance(); /// Added New line


    $this->form_validation->set_rules('username', 'Username', 'required|trim|xss_clean');
    $this->form_validation->set_rules('password', 'Password', 'required|md5|xss_clean');
    $this->form_validation->set_error_delimiters('<span class="error">', '</span>');

    if($this->form_validation->run()==FALSE) {
        $this->load->view('v_admin_login');
    } else {
        $username = $this->input->post('username');
        $password = $this->input->post('password');

        $cek = $this->m_admin_login->getAdmin($username, $password, 1, 1);

        if($cek <> 0) {
            $this->session->set_userdata('isLogin', TRUE);
            $this->session->set_userdata('username',$username);
            $this->session->set_userdata('level',$level);

            redirect('admin');
        } else {
      /// Added New Section
           $this->theme->set_message('Your error Msg', 'error');
           $data = array("username" => $this->input->post('username');,
                "password" => $this->input->post('password');,
                "ci" => $CI
            );
        }
    }

    $this->theme->view($data, "Your view page"); /// Added New line

}

Bây giờ trong quan điểm

Đặt dòng này nơi bạn muốn hiển thị tin nhắn

<?php echo $ci->theme->message(); ?>   /// Added New line

Đúng rồi. Có khả năng nó chỉ hoạt động nếu bạn cũng sử dụng thẻ đóng:

Bạn luôn có thể thấy những gì đang diễn ra bằng cách sử dụng bảng điều khiển phát triển trình duyệt web của bạn.
(This post was last modified: 12-09-2019, 08:11 PM by richb201.)


Bạn đã thử gì? & Nbsp; bạn đã làm gì?

$this->load->view("javascript_funcs_extensionloaded","snapshot_mode2");->load->view("javascript_funcs_extensionloaded","snapshot_mode2");

Đã tham gia CodeIgniter Community 2009. & nbsp; & nbsp; (Skype: insitfx)

12-10-2019, 08:01 PM (Bài đăng này được sửa đổi lần cuối: 12-10-2019, 08:39 PM bởi Richb201.)[font=DejaVu Sans Mono]javascript_funcs_extensionloaded file, but they never get triggered. So either phpStorm is not allowing me to debug a js file, or the js file is not really loading or being called correctly. Any idea on how to resolve this? [/font]

bằng chứng rằng một con chó già có thể học các thủ thuật mới


Đúng rồi. Có khả năng nó chỉ hoạt động nếu bạn cũng sử dụng thẻ đóng:richb201 Wrote: My php code is running along fine. At some point I make this call:
$this->load->view("javascript_funcs_extensionloaded","snapshot_mode2");

$ this-> load-> Xem ($ Tệp, $ Data) & nbsp; Giả sử rằng tệp là tệp PHP trong thư mục ứng dụng/chế độ xem. Nếu bạn có tệp javascript_funcs_extension đã tải.php, trong đó - bật - tải một tệp javascript trong thư mục /js của bạn, hãy đảm bảo bạn thực hiện tham chiếu chính xác đến thư mục JS. Cách tốt nhất IMO là:
If you have a javascript_funcs_extensionloaded.php file, which - on it's turn - loads a javascript file in your /js folder, make sure you make the correct reference to the js folder.
Best way IMO is:

Mã PHP:

<script src="<?= base_url();?>js/script_filename.js" /> 

Đặt mã này ở đầu quan điểm của bạn.

12-10-2019, 06:19 AM (Bài đăng này được sửa đổi lần cuối: 12-10-2019, 06:19 AM bởi Richb201.)
(This post was last modified: 12-10-2019, 06:19 AM by richb201.)


Hãy xem nếu tôi hiểu? Tôi nên thay đổi dòng trong tệp PHP gọi của mình thành:

$ this-> load-> view ('javascript_funcs_extension đã tải.php');

Và ở đầu javascript_funcs_extension đã tải.php tôi nên có