将动态数据从控制器传递到具有已定义脚本的视图,该脚本使用该动态数据加载php视图

I am new to MVC and working on a video calling facility between two parties where an admin schedules a call between two the two parties and stores the randomly generated room number in a table.

Okay some background first, there are some patients and a doctor. An admin schedules a call between them. Whenever a patient or a doctor clicks on video call first an ajax query calls a function and checks if there is an entry for the patient/doctor using their id's in the schedule table and if it's there it calls the video chat view.

So to set up video calling I have used a script in the views page which randomly generates a room number(Here I need to get that room number from the table and not generate a random one). I need some help here. I just cannot call the webpage directly using the controller without passing the room number.

I have tried passing the room number to the controller but doesn't seem to work and I am completely confused on how to execute it because of the way how php webpages work Any help would be appreciated.

1st - This is my view page for the patient where the ajax method checks if there's an entry and then opens the window for video chat


 $(document).on('click','#create_call', function(){

    var case_id=$(this).attr('class');
    $('#case_id_get').val(case_id);

    $.ajax({
            url: "<?php echo base_url('video/checkpatient');?>",
            type: "post",
            data: {case_id:case_id},
            success: function(response)
            {
                if(response==1)
                {
                    var newwindow = window.open('video/videochat');
                }
                else
                {
                    Messenger().post({
                        message: 'NO ENTRY FOUND',
                        type: 'error',
                        showCloseButton: true
                    });
                }
            }
        });


    });

video is my controller and checkpatient and videochat are its functions. Here's the controller within the functions


    public function videochat()
    {

            $views = array('video/webcam.php');
            $data = array('views'=>$views);
            $this->load->view('template/main',$data);
    }

    public function checkpatient()
    {
        $case_id = $this->input->post('case_id');
        $checkentry = $this->Call_Schedule->CheckPatientEntry($case_id);
        if($checkentry->num_rows()>0)
        {
            echo '1';
            exit;
        }
        echo '0';

    }

As you can see when I call videochat it opens a page named webcam.php which contains my script to start call.

<style>
    video {
  -webkit-transform: scaleX(-1);
  transform: scaleX(-1);
  }
  </style> 
  <div>
    <video id="localVideo" autoplay></video>
    <video id="remoteVideo" autoplay></video>
  </div>
<script>



hash = Math.floor(Math.random() * 0xFFFFFF).toString(16); 
const roomnumber = hash;
// Here I want the roomnumber to be used from the table not use the randomly generated number.

// other code to run the video call

How do I get the room number from the table corresponding to a patient/doctor?

Here You Have passed echo '1' which is string but in response u have checked response == 1 which is int

in controller

public function checkpatient()
    {
        $case_id = $this->input->post('case_id');
        $checkentry = $this->Call_Schedule->CheckPatientEntry($case_id);
        if($checkentry->num_rows()>0)
        {
            echo '1';  // change to '1' to 1  string to int 
            exit;
        }
        echo '0';

    }

In Script

$.ajax({
            url: "<?php echo base_url('video/checkpatient');?>",
            type: "post",
            data: {case_id:case_id},
            success: function(response)
            {
                if(parseInt(response)==1) // change from stringt  to  int 
                {
                    var newwindow = window.open('video/videochat');
                }
                else
                {
                    Messenger().post({
                        message: 'NO ENTRY FOUND',
                        type: 'error',
                        showCloseButton: true
                    });
                }
            }
        });

If this is not the cause please clarify that if case id is being printed in checkpatient() function or not