Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Ajax Banner rotator

  1. #1

    Ajax Banner rotator

    Salve,
    Mi scuso per prima!
    Premetto che sono meno che un principiante nel settore!
    Online sono riuscito a trovare uno scirpt per la rotazione dei banner!
    Questi sono i codici dei file originali:

    File ajax-banner.js da sorvolare (funziona non è qui il problem)

    Codice PHP:
    function makeHttpRequest(urlcallback_functionreturn_xml)
    {
       var 
    http_request false;

       if (
    window.XMLHttpRequest) { // Mozilla, Safari,...
           
    http_request = new XMLHttpRequest();
           if (
    http_request.overrideMimeType) {
               
    http_request.overrideMimeType('text/xml');
           }

       } else if (
    window.ActiveXObject) { // IE
           
    try {
               
    http_request = new ActiveXObject("Msxml2.XMLHTTP");
           } catch (
    e) {
               try {
                   
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
               } catch (
    e) {}
           }
       }

       if (!
    http_request) {
           
    alert('Unfortunatelly you browser doesn\'t support this feature.');
           return 
    false;
       }
       
    http_request.onreadystatechange = function() {
           if (
    http_request.readyState == 4) {
               if (
    http_request.status == 200) {
                   if (
    return_xml) {
                       eval(
    callback_function '(http_request.responseXML)');
                   } else {
                       eval(
    callback_function '(http_request.responseText)');
                   }
               } else {
                   
    alert('There was a problem with the request.(Code: ' http_request.status ')');
               }
           }
       }
       
    http_request.open('GET'urltrue);
       
    http_request.send(null);
    }

    function 
    loadBanner(xml)
    {
        var 
    html_content xml.getElementsByTagName('content').item(0).firstChild.nodeValue;
        var 
    reload_after xml.getElementsByTagName('reload').item(0).firstChild.nodeValue;
        
    document.getElementById('ajax-banner').innerHTML html_content;

        try {
            
    clearTimeout(to);
        } catch (
    e) {}

        
    to setTimeout("nextAd()"parseInt(reload_after));


    }

    function 
    nextAd()
    {
        var 
    now = new Date();
        var 
    url 'ajax-banner.php?ts=' now.getTime();
        
    makeHttpRequest(url'loadBanner'true);
    }

    window.onload nextAd

  2. #2
    non riesco a postare il resto

  3. #3
    continua.....
    non riuscivo a postare tutto in una volta!

    File ajax-banner.php

    Codice PHP:
    <?php

    $option 
    2;
    $reload 5000;
    //parte opzione 1 tagliato

    elseif ($option == 2) {

    // Simply add the banners you would like to display.
    // You can use HTML to display Images - or just plain HTML.  You can even put display a form or a flash aplet :)
    // You cannot display javascript :(
    $banners = array (
        
        
    'This Is A Text String',
        
    '<h1>Some HTML</h1>',
        
    '[img]banner.gif[/img]',

    );

    session_start();
    if (
        !isset(
    $_SESSION['ajax_banner']) // not yet set
        
    ||
        (
    $_SESSION['ajax_banner'] == count($banners) - 1// already at the end
       
    ) {
        
    $_SESSION['ajax_banner'] = 0// start from the beginning
    } else {
        
    $_SESSION['ajax_banner']++; // increment to the next
    }

    $html $banners[$_SESSION['ajax_banner']];
    }

    // You don't need to edit anything after this point!

    // send XML headers
    header('Content-type: text/xml');
    echo 
    '<?xml version="1.0" ?>';

    // print the XML response
    ?>

    <banner>
        <content><?php echo htmlentities($html); ?></content>
        <reload><?php echo $reload ?></reload>
    </banner>

  4. #4
    Voglio personalizzare questo caricando nell'array $banners dei dati da mysql;
    La query la devo fare nella stessa pagina,o come devo fare?
    Per visualizzare l'output inserisco il seguente codice nella pagina banner.php

    Codice PHP:
    <script src="ajax-banner.js" type="text/javascript"></script>
    <div align="center" id="ajax-banner"></div> 
    Che poi includo banner.php in tutte le pagine del sito.

    Ho già testato la prima soluzione(query nel file ajax-banner.php) è funziona, ma non in tutte le pagine del mio sito
    Quale può essere il problema?Devo mettere la query da un'altra parte?

  5. #5
    Tornando all'errore, nella pagina in cui non funziona ho un altro javascript,precisamente un preloader!
    Se lo tolgo lo script del preloader, allora il banner si visualizza!
    Cosa sbaglio?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.