PDA

View Full Version : Ajax Rotating Includes - Can I call the code from an external page?



beck.thomson
06-27-2008, 04:57 PM
1) Script Title: Ajax Rotating Includes

2) Script URL: http://www.dynamicdrive.com/dynamicindex17/ajaxrotate.htm

I'd like to be able to call the javascript from an external page, thus avoiding the lengthy code at the top of the page. I really know nothing about javascript, although I have done this successfully in the past...

Here's what I tried:


<script type="text/javascript" src="resources/rotating_content.js">
ajaxinclude(includefiles, "random")
</script>


My pages is here:
http://www.sweetsomethingschocolate.com/testing/

Thanks for any help you can give me--I feel like this should be a relatively simple answer, but I could definitely be wrong. :)

CyberGhost
06-28-2008, 10:05 AM
Hi,

I would suggest to use the jQuery framework in order to accomplish this.
I use it myself and it's proven both effective and compatible.

Simply download jQuery (I'd suggest the minified version) from http://jquery.com.
Then, on your website, just put this snippet of code:

<script type="text/javascript" src="jquery_1_2_6.js"></script>
... replace 'jquery_1_2_6.js' by whatever name you call your jQuery file.

I'd suggest putting this code at the end of page, i.e.:


<script type="text/javascript" src="jquery_1_2_6.js"></script>
</body>



Then, you can call your external JavaScript file like this:

$.getScript('external.js', function(data) {
alert('This message is shown when the file has been successfully loaded.');
});


Hope this helps.
Cyber