0

I am calling a JSON source with jQuery that looks like this:

{
   total: 1,
   current: 0
}

My jQuery script below is returning NULL from the json call and I can't work out why? The data source is correct and working.

    $.ajax({
        url: source,
        cache: false,
        beforeSend: function(){
            target.before('<div class="feed-loading"></div>', function(){
                target.slideUp();
            });
        },
        success: function(html){

            /* load feed data into target */

            target.html(html).slideDown();
            $('.feed-loading').fadeOut();

            /* updates attendances */

            $('.actionpanel a.attend').each(function(index) {

                var event_id = $(this).attr('rel');

                /* find if logged in user is attending */

                $.getJSON(settings.base_url + 'ajax/event_attendance/' + event_id, function(attendance) {

                    console.log(attendance);

                    /* update attendance figures on page */

                    $('a.attend[rel="' + event_id + '"]').nextAll('.meta').text(attendance.total + ' attending');

                    if (attendance.current == 1) {
                        $('a.attend[rel="' + event_id + '"]').addClass('selected').attr('title', 'You are attending!');
                    };

                });

            });
        }
    });

I think it must be something to do with the fact its within another ajax call as I have used similar code elsewhere and its worked ok.

1 Answer 1

2

I think your JSON is bad -- you're missing a comma. Try this:

{
   total: 1,
   current: 0
}
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, seems to be a copy paste issue. The json does actually have a comma. Thanks anyway.

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.