jQuery .load doesn't load swfobject content
I'm loading some content (NOT THE HTML headers or anything, just HTML formatted content from a PHP) via jquery .load() into a div.
It works, perfectly for everything BUT some Flash-based amCharts (www.amcharts.com) dynamically loaded with amCharts PHP, using swfObject. The file, loaded seperately, works and loads the Flash charts. When being loaded in using .load() the file seems to be loaded, but scripts not executed and swfObject not enacted.
Now, i'm not sure what code to give you here, so ill just give some stuff around it...
So, in header of main parent is the code listening for the nav click to load the content (which is our amcharts):-
$('a.leftNav').click(functi开发者_Python百科on() {
page = $(this).attr('page');
metID = $(this).attr('metID');
if($("#mainRight").is(":visible")) { $('#mainRight').hide(200); }
switch(page) {
case 'metrics': $("#mainRight").load("content.php?load=mets", { metID: '5000227' }); break;
}
$('#mainRight').show(300);
});
So that works. Loads the correct page and works executing the PHP as proved by going to the page content.php?load=mets. The code on that page generated by the PHP is:-
<div class="amChart" id="chart_views_div">
Chart loading ...
That should be the exchanged swfObject code, which I know (i've outputted to a text file the PHP's code generated) is working.
What happens with .load() and loaded swfObject and JS generally?
You need to call a function to initialise the swfObject replacement when jquery .load()
has completed as i believe that swfObject would usually initialise on window.load.
something like this:
$("#mainRight").load("content.php?load=mets", function() {
// initialise swfObject here e.g.
swfobject.embedSWF("myContent.swf", "chart_views_div", "300", "120", "9.0.0");
});
Am Charts still uses swfobject 1.5
Swfobject 2.x offers much more IMHO amcharts should update to use the new version.
2.x has createswf which should be used in this case
精彩评论