ajax php

Gestart doorSmiegles10 reacties136 weergaven

11 berichten · pagina 1 van 1

Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
he
ik ben deze code

<script>
function Ajax(){
var xmlHttp;
    try{    
        xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
    }
    catch (e){
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
        }
        catch (e){
            try{
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){
                alert("No AJAX!?");
                return false;
            }
        }
    }

xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4){
        document.getElementById(herlaad).innerHTML=xmlHttp.responseText;
        setTimeout(Ajax(),10000);
    }
}
xmlHttp.open("GET","http://127.0.0.1/forum/online.php?id=[COLOR= #0000BB]<?php[/COLOR] 
         [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]) &&[/COLOR] [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ip[/COLOR][COLOR= #007700]])
        {[/COLOR]
                [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]))
            {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]];
            }
        }[/COLOR]
        ?>",true);
xmlHttp.send(null);
}

window.onload=function(){
    setTimeout(Ajax(),10000);
}
        </script>


deze herlaad het online leden.
echter wil ik dezelfde code gebruiken voor het herladen van de topics zodat je niet de pagina hoeft te herladen om nieuwe berichten te bekijken.
alleen ik kan niet 2x dezelfde code gebruiken want dan werkt het niet meer,
iemand die mij hiermee kan helpen zodat dat wel kan?

mvg ,

smiegles
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je noemt deze function Ajax, maak er nog een en noem die Ajaxx ofzo. Maar alle topics herladen laat je site sloom gaan. Daar weet ik alles van...
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Vind jij Ajaxx een logische naam?

Ik zou eerder een aparte ajax functie maken die de XmlHttpRequest actie uitvoert.
En losse functies maken voor de dingen die je aanroept. Daarvoor kan je dan de AJAX-functie gebruiken.

Ikzelf gebruik altijd jQuery, een stuk makkelijker in gebruik.
0
Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
Vind jij Ajaxx een logische naam?

Ik zou eerder een aparte ajax functie maken die de XmlHttpRequest actie uitvoert.
En losse functies maken voor de dingen die je aanroept. Daarvoor kan je dan de AJAX-functie gebruiken.

Ikzelf gebruik altijd jQuery, een stuk makkelijker in gebruik.
heb je een voorbeeldje?
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Smiegles schreef:
Eerdere citaten tonen
Aarclay schreef:
Vind jij Ajaxx een logische naam?
Ik zou eerder een aparte ajax functie maken die de XmlHttpRequest actie uitvoert.
En losse functies maken voor de dingen die je aanroept. Daarvoor kan je dan de AJAX-functie gebruiken.

Ikzelf gebruik altijd jQuery, een stuk makkelijker in gebruik.

heb je een voorbeeldje?
google >> "jQuery .load"
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Hoezo load?
Je wilt niet altijd iets zichtbaar via ajax laden...

Google liever op jquery en ajax...

De $.ajax() functie is meestal het handigste, of $.get() en $.post() als shorthand.
0
Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
hi ,

ik ben al 6 dagen aan het zoeken maar ik kan echt niks vinden.
is er iemand die me kan helpen?
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Als ik Ajax invul op www.jquery.com kom ik toch echt een hoop handig leesvoer tegen.
0
Thom

Lid

Berichten
10.654
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript">
<script type="text/javascript">
function reloadForum(){
var id = "[COLOR= #0000BB]<?php[/COLOR] 
         [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]) &&[/COLOR] [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ip[/COLOR][COLOR= #007700]])
        {[/COLOR]
                [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]))
            {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]];
            }
        }[/COLOR]
?>";
$.get("http://127.0.0.1/forum/online.php", { id: id },function(data) { $(#herlaad).html(data); });
setTimeout(reloadForum(),10000);
}
$(document).ready(function(){
reloadForum();
});
</script>


Zou ik doen
0
Smiegles

Lid · Topicstarter

Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Thommiee schreef:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript">
<script type="text/javascript">
function reloadForum(){
var id = "[COLOR= #0000BB]<?php[/COLOR] 
         [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]) &&[/COLOR] [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]ip[/COLOR][COLOR= #007700]])
        {[/COLOR]
                [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]))
            {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]];
            }
        }[/COLOR]
?>";
$.get("http://127.0.0.1/forum/online.php", { id: id },function(data) { $(#herlaad).html(data); });
setTimeout(reloadForum(),10000);
}
$(document).ready(function(){
reloadForum();
});
</script>
Zou ik doen

enorm bedanktthumbsup
0
Thom

Lid

Berichten
10.654
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Het is heel erg simpel.. jquery.com
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren