1

i am stuck at some json parsing, i am populating some fields using jquery's ajax function, i found the desired result, but dont know how to print it, here is my code

function logged_in_users() {
    $.ajax({
        url: site_url+'user/get_loggedin_users',
        dataType : 'json',
        success: function(result) {
            $('#div_id').append(result.email_address)
        }
    }); 
}

while i have a result in my console response like,

[{"email_address":"[email protected]"},{"email_address":"[email protected]"}]

while on the function side i am using,

echo json_encode($this->login_history_model->get_logged_in_users());

Any help will greatly be appreciated

1 Answer 1

3

You've got an array of results, not just one result, so your success function won't work.

Change to:

success: function(result) {
    $.each(result, function(i, v) {
        // For each record in the returned array
        $('#div_id').append(v.email_address); 
    });
}
Sign up to request clarification or add additional context in comments.

3 Comments

Haha, early bird catches the worm and all that.
@Chris Dixon, simply Superb!
@Barmer, Thank you for your attention, please contribute a little to show a gif image while ajax function is fetching records, Thanks in advance

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.