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

    problema con ajax e include

    Ciao a tutti!
    ho un problemone con uno script che posto qui sotto:

    <html>

    <head>

    <script type="text/javascript">
    var page = "show_news.asp";
    function ajax(url,target)
    {
    // native XMLHttpRequest object
    document.getElementById(target).innerHTML = 'sending...';
    if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = function() {ajaxDone(target);};
    req.open("GET", url+"?sid="+Math.random(), 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+"?sid="+Math.random(), true);
    req.send();
    }
    }
    setTimeout("ajax(page,'scriptoutput')", 10000);
    }
    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;
    }
    }
    }
    </script>

    </head>
    <body onload="ajax(page,'scriptoutput')" >

    <DIV id="scriptoutput" >ciao</DIV>




    </body>
    </html>




    Così come lo vedete voi funziona alla perfezione, ma appena inserisco un include tipo questo: ... Addio salta tutto e non vedo nulla solo il file compreso nell'include. perche??????

    Se qualcuno potrà aiutarmi gliene sarò grata per la vita

    Ciao e buon lavoro a tutti
    www.mediatribe.it
    mediatribe@artesoftware.it

  2. #2
    Allora io posto la soluzione che ho trovato spero serva a qualcuno

    <html>
    <head>
    <script type="text/javascript">
    var page = "show_news.asp";
    function ajax(url,target)
    {
    // native XMLHttpRequest object
    document.getElementById(target).innerHTML = 'sending...';
    if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = function() {ajaxDone(target);};
    req.open("GET", url+"?sid="+Math.random(), 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+"?sid="+Math.random(), true);
    req.send();
    }
    }
    setTimeout("ajax(page,'scriptoutput')", 2000);
    }
    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;
    }
    }
    }
    </script>


    </head>

    <body>


    link
    <script>document.getElementById('scriptoutput').on click();</script>


    </body>
    </html>

    Questa soluzione funziona anche con l'include
    Un bacione a tutti
    www.mediatribe.it
    mediatribe@artesoftware.it

  3. #3
    ragazzi non ho risolto perchè non mi apre il link nel contenuto del div

    Sono al punto di partenza quindi è ancora valido il quesito degli include ..... scusate
    www.mediatribe.it
    mediatribe@artesoftware.it

  4. #4
    Utente di HTML.it L'avatar di Pastore12
    Registrato dal
    Oct 2008
    Messaggi
    1,051
    Ciao! Sto cercando di capire come funzionano i tuoi codici, ma non ci capisco molto...

    Però ti faccio tre domande:

    1. Puoi mettere il tuo codice tra i tag [ php ] [ /php ] ?
    2. Poi riportare il codice html che salterebbe fuori dalla chiamata all'include? Non il codice dell'asp perchè non ho gli strumenti per compilarlo, se è questo il termine giusto.
    3. Saresti disposta ad adottare un framework per javascript come jQuery? E' opensource e semplifica molto la vita nelle chiamate ajax. Eppoi un po' lo conosco..

    Ciao!
    "Ethics are to me something private. Whenever you use it as an argument for why somebody_else should do something, you’re no longer being ethical, you’re just being a sanctimonious dick-head"
    Linus Torvalds

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.