Hailwood
Hailwood

Reputation: 92581

fancybox - show ajax content?

I have an anchor tag with a click event on it

$('a').click(function(){
  $.ajax({
    url:     'ajax/test.php',
    data:    {id: 123, count: 456},
    success: function(data) {
               //lightbox data
             }
  });
});

The response will look something like

{
  title: 'My Title',
  body:  'My Body'
}

I want to show this in a fancybox.

Where I am stuck is creating and showing a fancybox around this content on the fly?

Upvotes: 1

Views: 4905

Answers (1)

Jarrett Widman
Jarrett Widman

Reputation: 6419

Have you tried something like this?

success: function(data) {
  $.fancybox({
    'content' : '<h1>' + data.title + '</h1>' + data.body
  });
}

Upvotes: 11

Related Questions