Recently, I have been experimenting with incorporating Google Charts into my website to showcase data from Google Analytics.
To enhance user experience, I decided to split my analytics reports into distinct sections such as Pages, Browsers, Operating Systems, and Traffic sources.
I developed a handler that manages the requests and triggers an ajax call to a designated file. For instance, when requesting Pages, the handler initiates an ajax loading graphic and calls ajax_pages.php. Upon completion, it adds the HTML content to a specific div element.
However, I encountered a perplexing issue - embedding Google Charts code within any of the ajax_*.php files fails to load the JavaScript entirely. Oddly enough, other JavaScript codes function perfectly fine. I even tested by using
<script>alert('aaaa');</script>
, which executed without a hitch. Strangely, the Google Charts JavaScript code does not even appear in the page's source code. This inconsistency is puzzling since some form of error message or indicator should be present.
An effective workaround I discovered was placing the code before the handler sends the request, resulting in successful display of the charts.