Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    ajax + asp..errore di refresh

    Ciao a tutti,

    ho trovato su google questo codice che mi permette di aggiornare un div posizionato in beta.asp ogni tot di second in maniera automatica.

    Contenuto beta.asp:
    <head>
    <script type="text/javascript">
    var page = "test.asp";
    function ajax(url,target)
    {
    // native XMLHttpRequest object
    document.getElementById(target).innerHTML = '<label class="toggleborder">[img]ajaxtabs/loading.gif[/img] verifico stato online...</label>';
    if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = function() {ajaxDone(target);};
    req.open("GET", url, true);
    req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
    req.onreadystatechange = function() {ajaxDone(target);};
    req.open("GET", url, true);
    req.send();
    }
    }
    setTimeout("ajax(page,'scriptoutput')", 50000);
    }

    function ajaxDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
    // only if "OK"
    if (req.status == 200 || req.status == 304) {
    results = req.responseText;
    document.getElementById(target).innerHTML = results;
    } else {
    document.getElementById(target).innerHTML="ajax error:\n" +
    req.statusText;
    }
    }
    }

    window.onload=function(){
    ajax(page, 'scriptoutput');
    }
    </script>
    <head>

    <span id="scriptoutput"> qui finisce il refresh ogni 50secondi</span>





    la pagina test.asp invece contiene il seguente codice ( non è quello che stò usando al 100% veramente ma ho preso un facs-simile sempre su google):

    <%
    If isCommonCreated <> True Then

    'Determino le dimensioni delle variabili
    Dim strDataBasePath 'Variabile
    Dim cString 'Variabile
    Dim adoCon 'Variabile
    Dim strSQL 'Variabile

    'Setto la variabile per una connessione ADO
    Set adoCon = Server.CreateObject("ADODB.Connection")

    '------------------------------------------------------------------------------------
    'Cambiare il path del database
    strDataBasePath = "db/utenti.mdb"
    '------------------------------------------------------------------------------------

    'Stringa per la connessione
    'Se la seguente linea non funziona, commentare con ' e scegliere un altra stringa
    cString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(strDataBasePath)

    'Usa questa stringa se usi Access Database 2000 o 2002
    'cString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(strDataBasePath)

    'Usa questa stringa se usi DSN
    'cString = "DSN=utenti"
    '

    adoCon.Open cString

    'Richiesta dei valori utente

    'Setta the variable to the value in the users cookie
    str_userscode = Request.Cookies("Login")("userCode")

    'Se l'user code non è vuota allora
    IF str_userscode <> "" THEN
    'Creo un nuovo record set
    Set rsUserLog = Server.CreateObject("ADODB.RecordSet")

    'Setta una nuova stringa sql
    StrSql="SELECT * FROM tbl_authors WHERE code='" & str_userscode & "';"

    'Apro il recordset e eseguo il codice sql
    rsUserLog.open StrSql,cString

    'Se non ci sono record che accertano l'identita dei dati dai cookies dell'utente
    'setta la variabile vuota

    If rsUserLog.EOF Then
    Response.cookies("Login")("userCode") = ""
    'Se non c'è nessun record allora
    Else

    ' Setta i valori del database con le variabili
    str_users_name = rsUserLog("name")
    str_users_password = rsUserLog("pass")
    str_users_nome = rsUserLog("nome")
    str_users_cognome = rsUserLog("ultimoaccesso")
    End If

    'Chiudo
    rsUserLog.Close
    set rsUserLog = Nothing

    'Se l'user code è vuoto allora l'utente è guest
    Else
    Response.cookies("Login")("userCode") = ""
    End If

    Else
    Dim isCommonCreated
    isCommonCreated = True
    End If

    '--------------------------------------------------------------------------------------------
    Function GetState(intState)
    Select Case intState
    Case 0
    GetState = "adStateClosed"
    Case 1
    GetState = "adStateOpen"
    End Select
    'Sintassi: GetState(adoCon.state)
    End Function
    '--------------------------------------------------------------------------------------------
    %>


    e sempre in test.asp ho inserito un controllo sull'ultimo accesso dell'utente..in modo che se è maggiore di 2 minuti aggiorna il database:

    dim Minuti
    Minuti = DateDiff("n", str_users_ultimoaccesso, Now())

    If Minuti > 3 Then
    strSQL = "UPDATE tbl_authors SET ultimoaccesso = now() WHERE name = '" & str_users_name & "'"
    adoCon.execute strSQL
    End If

    Il grosso problema è che dopo tot di tempo
    viene effettuata la disconnesione dal sito in automatico..come mai?

    Ricordo che i codici he postato sono solo indicativi rispetto a quelli che stò usando nella mia community

    Grazie a tutti per la pazienza, e il possibile aiuto che riuscirete a darmi..qualsiasi ipotesi v venga in mente postatela!

    ciaooo

  2. #2
    se vi servono maggiori indicazioni o non è chiaro quello che ho scritto fatemi sapere..

  3. #3
    forse la disconnessione non dipendeva da quello script!

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.