动态URL通过Jquery

时间:2013-10-11 06:49:11

标签: php jquery json codeigniter

我有以下脚本:

 <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>

我想通过在链接末尾添加一个变量(id)来创建动态网址,使其成为href =“profile / details / id。我该怎么做?

2 个答案:

答案 0 :(得分:3)

waiting.id中附加href,例如 href =“个人资料/详细信息/'+ waiting.id +'”

<强>代码,

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 ---------------^---------
           });
},

答案 1 :(得分:1)

尝试

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