views:

53

answers:

2

Hello, 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(function() {
            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?

+1  A: 

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");
});
seengee
Sounds about right. But, what does a function to initalise swfObject look like? I'm not having much fun.
WiseDonkey
added an example above
seengee
Thank you. Unfortunately, I'm using a amCharts PHP, which loads a particular verison of swfobject in its own way. So I might be screwed. Is this something I can run on the page, once loaded - like an event which makes sure the swfObject is loaded. This .load() at the moment, exists in the parent docu, which is loading the content.php.
WiseDonkey
does your returned code contain the required javascript? its possible you just need to eval that
seengee
A: 

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

sam