nested loops in ajax-json