1

I'm using fancybox2 to open a new html. Here I generate html through jquery ajax method. But fancybox2 don't respond. Here is the code

 var Line = $.ajax({ type: "GET",
           url: "/ajaxHTML",
           dataType: 'html',
           success: function(result){alert(result);},
           }).responseText;

 $.fancybox.open({ 'content' : Line}, {type: 'html'});

Am I using it wrongly? I can open fancybox with simple text or html code. But not with this responseText variable. And ajax can get html successfully. Alert function works and shows the content of whole html page.

user2189731
  • 558
  • 8
  • 15

1 Answers1

0

Try :

$.fancybox.open(Line,{
    type: 'html'
});

... or

$.fancybox.open({
    content : Line,
    type: 'html'
});

See JSFIDDLE

JFK
  • 40,963
  • 31
  • 133
  • 306
  • Both are not working. Maybe my html is too complicated? I'm using the whole webpage including scripts/title/head/body/etc. Any limitations on html format for content? – user2189731 Mar 22 '13 at 00:30
  • since it's a whole html page, maybe you need to change to `type: 'iframe'` – JFK Mar 22 '13 at 01:09
  • I guess so. I'll try it and see if it helps. I'm not an expert in html/js, is iframe could support auto-load instead of a click? My application will not show this html by default and I hope it to pop up a window with fancybox when certain even happens. Here I'm using google chart, I'm not sure how google chart could work with fancybox. – user2189731 Mar 23 '13 at 03:13
  • Or I'm not sure whether iframe can support dynamic content or not. I want to show a google chart on select, but the chart is dynamically generated. So by default there is nothing in iframe. Could you share some thoughts or codes to let iframe work like this? – user2189731 Mar 23 '13 at 04:09
  • now sure whether this will work or not:var iframeDoc = myIframe.contentWindow.document; iframeDoc.open(); iframeDoc.write('hello world'); iframeDoc.close(); – user2189731 Mar 23 '13 at 04:20
  • @user2189731 : check this http://stackoverflow.com/a/11739627/1055987 if that helps – JFK Mar 23 '13 at 07:31
  • It seems a button is inevitable. Thanks JFK for your patience. – user2189731 Mar 25 '13 at 07:28