0

I have the following script :

 <script>
    $(document).ready(function(){
        setInterval(function() {
            $.ajax({
                type: "GET",
                url: "<?php echo base_url(); ?>profile/load_data",
                dataType: "JSON",
                success: function(people) {               
                    waiting_list=$('#waiting_list').empty();

                    $.each(people, function(i, waiting){                    
                    waiting_list.append('<a href="profile/details">'+waiting.id+" "+waiting.lname+" "+waiting.sname+'</a>');
                    });
                },
                error: function(data) {
                  //  alert('An error occured, kindly try later');
                }
            });
        }, 10000);


    });
</script>

I want to create a dynamic url by adding a variable (id) at the end of the link to be href="profile/details/id . How can I do this?

2 Answers 2

3

Append waiting.id in href like href="profile/details/'+waiting.id+'"

Code,

success: function(people) {               
           waiting_list=$('#waiting_list').empty();
           $.each(people, function(i, waiting){     
               id=waiting.id;
               lname=waiting.lname;
               sname=waiting.sname;
               waiting_list.append('<a href="profile/details/'+id+'">'+id+" "+lname+" "+sname+'</a>');
                              // Append id here ---------------^---------
           });
},
Sign up to request clarification or add additional context in comments.

Comments

1

Try

waiting_list.append('<a href="profile/details/'+waiting.id+'">'+waiting.id+" "+waiting.lname+" "+waiting.sname+'</a>');
});

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.