Results 1 to 5 of 5

Thread: multiple instances of Ajax Rotating Includes Script trouble

  1. #1
    Join Date
    Dec 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default multiple instances of Ajax Rotating Includes Script trouble

    Great script! The description says that you can call the script several times on a page, and be able to change the ARRAY and the INCLUSION.
    We want to have one instance of a daily script from one array, and another random script from a different array.
    Where do you add the second array? We have tried the following:

    var includefiles=["featured/cigar1.html", "featured/cigar2.html", "featured/cigar3.html", "featured/cigar4.html", "featured/cigar5.html", "featured/cigar6.html", "featured/cigar7.html" ,"featured/monthly1.html"]

    var monthlyfiles=["featured/monthly1.html", "featured/monthly2.html", "featured/monthly3.html"]

    IS this actually creating a second array? It only displays content from the first array even though we have called it
    ajaxinclude(monthlyfiles, "random")

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    What you have there in your post looks correct. Are you sure you have followed all of the instructions/templates on the demo page, especially putting each instance of:

    Code:
    ajaxinclude(files_array, 'rotatetype')
    in its own script block on the page:

    Code:
    <script type="text/javascript">
    ajaxinclude(files_array, 'rotatetype')
    </script>
    with the main script inserted in the head section?

    Anyways, I'd need to see your page to see what's up with it, so either:

    PLEASE: Include the URL to your problematic webpage that you want help with.

    or:

    Post your code here, put code tags:

    [code]

    code goes here

    [/code]

    around your code in messages here so that it appears as it was when you copied it from your page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    We have done everything that you said, but it still only pulls from the first aray in both instances.
    We do reference the script externally in the head though - shouldn't matter should it?

    Here is the external .js file:

    <code>
    var includefiles=["featured/cigar1.html", "featured/cigar2.html", "featured/cigar3.html", "featured/cigar4.html", "featured/cigar5.html", "featured/cigar6.html", "featured/cigar7.html"]

    var monthlyfiles=["featured/monthly1.html", "featured/monthly2.html", "featured/monthly3.html"]

    var rootdomain="http://www.buymycigars.com"+window.location.hostname

    function ajaxinclude(files_array, rotatetype){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
    try {
    page_request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch (e){
    try{
    page_request = new ActiveXObject("Microsoft.XMLHTTP")
    }
    catch (e){}
    }
    }
    else
    return false
    var url=choosefile(files_array, rotatetype)
    if (typeof includefiles[url]=="undefined"){
    document.write("Error: No file for this day has been found.")
    return
    }
    else
    url=includefiles[url]
    page_request.open('GET', url, false) //get page synchronously
    page_request.send(null)
    writecontent(page_request)
    }

    function writecontent(page_request){
    if (window.location.href.indexOf("http")==-1 || page_request.status==200)
    document.write(page_request.responseText)
    }

    function choosefile(files_array, rotatetype){
    var today=new Date()
    var selectedfile=(rotatetype=="dailyw")? today.getDay() : rotatetype=="dailym"? today.getDate() : Math.floor(Math.random()*files_array.length)
    if (rotatetype=="dailyw" && selectedfile==0) //if display type=="week days" and today is Sunday
    selectedfile=7
    if (rotatetype=="dailyw" || rotatetype=="dailym")
    selectedfile-- //remove 1 to sync with array index
    return selectedfile
    }

    </code>


    Here is how we are placing the script in the page:

    <code>
    <div id="featuredcigarWeekly"><img src="images/featuredcigar.gif"><p>
    <script type="text/javascript">
    ajaxinclude(includefiles,"dailyw")
    </script>
    </p></div>
    <div id="featuredcigarMonthly"><img src="images/featuredmonthly.gif"><p>
    <script type="text/javascript">
    ajaxinclude(monthlyfiles,"random")
    </script>

    </code>

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This may be a bug in the script. I've never used it, didn't code it and don't fully understand it but, it seems to me that there is no way it can know what to do unless this:

    Code:
    function ajaxinclude(files_array, rotatetype){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
    try { . . .
    is changed to this:

    Code:
    function ajaxinclude(files_array, rotatetype){
    includefiles=files_array
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
    try { . . .
    By the way, when I said use [code][/code], I meant it, not <code></code>.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Dec 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Amazing how such a tiny bit of code can change everything.
    Works like a charm now - both arrays and both inclusions working seperately.Thank you so much for your help - and BTW, consider the request for [code] well taken!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •