Diasline
Diasline

Reputation: 635

Pass variable to link in loading view to div

May be the title is not corresponding to my following explanation. What I really mean is :

I store an input value in a jquery variable :

var id=$("#id-doc").val();

I have a div that is loading every second :

setInterval(function(){
$('#new_message1_doc').load("<?php echo base_url("medico/newMessageDoc")?>").fadeIn("slow");
}, 1000);

How can pass the variable id in the url to use it in controller function newMessageDoc ?

 function newMessageDoc()
 {
 echo $id;
 }

Thanks for your help

Upvotes: 0

Views: 33

Answers (1)

Lorenzo S
Lorenzo S

Reputation: 1397

In the javascript you take the id just inside the setInterval function, and you add it as a query param in the URL:

setInterval(function(){
    var id=$("#id-doc").val();
    $('#new_message1_doc').load("<?php echo base_url("medico/newMessageDoc")?>?id=" + id).fadeIn("slow");
}, 1000);

In the codeigniter code, you can get it using the input class:

 function newMessageDoc()
 {
     $id = $this->input->get('id');
     echo $id;
 }

Upvotes: 1

Related Questions