我希望使用json数组在php codeigniter中显示image_url

时间:2016-05-10 06:48:16

标签: javascript json

以下代码是通过数据库字段值的json对象。如何在json中显示图像代码是否正确请验证

$('#radio').one("click", function () {
    //    alert($(this).attr('id'));  //-->this will alert id of checked checkbox.
    if (this.checked) {

        $.ajax({
            method: "GET",
            url: "<?php echo base_url(); ?>index.php/secondpage/location",
            dataType: 'json',

            success: function (data) {
                console.log(data);
                var jsonObj = data;

                $('#tbody').append('');
                n = jsonObj.hotels.length;
                for (i = 0; i < n; i++) {

                    var eachrow = "<tr>"
                        + "<td>" + jsonObj.hotels[i].name + "</td>"
                        + "<td>" + jsonObj.hotels[i].location + "</td>"
                        + "<td><img src='" + jsonObj.hotels[i].image_url + "'></td>"
                        + "</tr>";
                    $('#tbody').append(eachrow);
                }
            }
        });
    }
});

以上代码是javascript以表格格式显示数据库值。 然后它显示相同的内容,但我也想要图像,但它不显示如何将图像路径添加到json表字段

0 个答案:

没有答案