0

I have the following

$id=$this->uri->segment(3);

I want to pass the variable data through a javascript url and I did it the following way :

<script>
$(document).ready(function(){
        setInterval(function() {
            $.ajax({
                type: "GET",                   
                url: "<?php echo base_url(); ?>pharm_profile/prescriptions/<?php $id; ?>",
                dataType: "JSON",
                success: function(prescription) {               
                    prescription_list=$('#prescription_list').empty();                        
                    $.each(prescription, function(i, prescription){                          
                       prescription_list.append('<div style="color: white;"><a style="color: white;" href="<?php echo base_url(); ?>pharm_profile/dispense_details/'+prescription.id+'">'+prescription.medname+'</a></a>\n\
            </br></div>');                        
                       // prescription_list.append('<li span="font_color:white !important;"><a href="<?php //echo base_url(); ?>transactions/details/'+prescription.medname+'">'+prescription.medname+'</a></li></a></br>');            
                    });
                },
                error: function(data) {
                    //alert(data);
                }
            });
        });


    });
</script>

When I run the script I only get url up to prescription leaving out the id. What is the best way to include the id?

3 Answers 3

1

You forget to add echo before the variable

Change the url or four ajax

url: "<?php echo base_url(); ?>pharm_profile/prescriptions/<?php $id; ?>",

to this

url: "<?php echo base_url(); ?>pharm_profile/prescriptions/<?php echo $id; ?>",
Sign up to request clarification or add additional context in comments.

Comments

1

Use echo to set the value $id,

url: "<?php echo base_url(); ?>pharm_profile/prescriptions/<?php echo $id; ?>",

Comments

0

Change this line, you are missing echo:

url: "<?php echo base_url(); ?>pharm_profile/prescriptions/<?php echo $id; ?>",

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.