Md Shyriad Rahman
Md Shyriad Rahman

Reputation: 1

Display Json data with ajax in codeignitor 4

My JSON data is available in browser console. But i cannot display data in template.

<script type="text/javascript">
    $(document).ready(function () {
    $.ajax({
        url:  '<?php echo_uri("clients/session_details") ?>',
        type: 'GET',        
        dataType: 'json',
        success: function(response) {
            var data = JSON.parse(response);
           $("#result").html(data[0].rx-byte);
       }
    });
    });
</script>

Upvotes: 0

Views: 36

Answers (1)

Chathura
Chathura

Reputation: 11

Based on the JSON data you provided, it seems like you are trying to display the rx-byte value in the HTML template. Here's a code sample that will do that:

$(document).ready(function () {
        $.ajax({
            url: '<?php echo_uri("clients/session_details") ?>',
            type: 'GET',
            dataType: 'json',
            success: function (response) {
                $("#result").html(response[0]["rx-byte"]);
            }
        });
    });

Upvotes: 1

Related Questions