Chatbox hulp.

Gestart doorMarvinn5 reacties21 weergaven

6 berichten · pagina 1 van 1

Marvinn

Lid · Topicstarter

Berichten
2.609
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoi.

Ik heb een heel slecht chat systeem die ik aan het opknappen ben, maar nu heb ik een probleem als ik een bericht plaatst refresht de hele pagina, ook het input veld waardoor je hem steeds weer moet selecteren.

Nu heb ik een vraag of iemand me kan helpen met ajax/javascript er in te maken dat niet de hele pagina moet herladen als er nieuwe berichten zijn, dit is denk te zwaar voor de server/het is vervelend.

Ik heb totaal geen verstand van die ajax dingen met load enzo.

chat_1.php is dit:

[COLOR= #0000BB]<?php[/COLOR] 
[URL="http://www.php.net/require_once"]require_once[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]../config.php[/COLOR][COLOR= #007700]);[/COLOR] 
[URL="http://www.php.net/ob_start"]ob_start[/URL][COLOR= #007700]();[/COLOR] 
?>
<html> 
<head> 
<title>Chat by nickjexx</title> 
<style type="text/css"> 
body { 
    font-family: Verdana; 
    font-size: 11px; 
    color: black; 
    margin: 0 auto; 
} 

input { 
    font-family: Verdana; 
    font-size: 11px; 
    color: black; 
} 

div#container { 
    width: 525px; 
    margin: 0 auto; 
} 

div#top { 
    background-image: url(../img/top.png); 
    height: 228px; 
    width: 525px; 
    margin: 10px 0 0 0; 
    padding: 13px 0px 0px 0px; 
} 

div#speech { 
    background-image: url(../img/speech.png); 
    height: 62px; 
    width: 525px; 
} 

input#chat-msg { 
    margin: 22px 0 0 65px; 
    background-color: transparent; 
    width: 465px; 
    border: 0; 
} 
</style> 
</head> 

<body> 
    <div id="container"> 
        [COLOR= #0000BB]<?php         
        $habbo[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]habbo[/COLOR][COLOR= #007700]];[/COLOR] 
        [COLOR= #0000BB]$hotel[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]hotel[/COLOR][COLOR= #007700]];[/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]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]logout[/COLOR][COLOR= #007700]])){[/COLOR] 
            [URL="http://www.php.net/setcookie"]setcookie[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"habbo"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"null"[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()-[/COLOR][COLOR= #0000BB]365[/COLOR][COLOR= #007700]);[/COLOR] 
            [URL="http://www.php.net/setcookie"]setcookie[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"hotel"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"null"[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()-[/COLOR][COLOR= #0000BB]365[/COLOR][COLOR= #007700]);[/COLOR] 
            [URL="http://www.php.net/setcookie"]setcookie[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"margin"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"null"[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()-[/COLOR][COLOR= #0000BB]365[/COLOR][COLOR= #007700]);[/COLOR] 
            [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Location: chat_1.php"[/COLOR][COLOR= #007700]); 
        }[/COLOR] 
         
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$habbo[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]null[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$hotel[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]null[/COLOR] [COLOR= #007700]|| ![/COLOR][COLOR= #0000BB]$habbo[/COLOR] [COLOR= #007700]&& ![/COLOR][COLOR= #0000BB]$hotel[/COLOR][COLOR= #007700]){[/COLOR] 
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR]login[COLOR= #007700]]){[/COLOR] 
                [COLOR= #0000BB]$hab[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]habbo[/COLOR][COLOR= #007700]]);[/COLOR] 
                [COLOR= #0000BB]$hot[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]hotel[/COLOR][COLOR= #007700]]);[/COLOR] 
                [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][COLOR= #0000BB]$hab[/COLOR] [COLOR= #007700]|| ![/COLOR][COLOR= #0000BB]$hot[/COLOR][COLOR= #007700]){[/COLOR] 
                    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Both fields are required!<br><br><a href="chat_1.php">&laquo; Back</a>[/COLOR][COLOR= #007700]; 
                }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR] 
                    [URL="http://www.php.net/setcookie"]setcookie[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"habbo"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$hab[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()+[/COLOR][COLOR= #0000BB]365[/COLOR][COLOR= #007700]);[/COLOR] 
                    [URL="http://www.php.net/setcookie"]setcookie[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"hotel"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$hot[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()+[/COLOR][COLOR= #0000BB]365[/COLOR][COLOR= #007700]);[/COLOR] 
                    [URL="http://www.php.net/setcookie"]setcookie[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"margin"[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/mt_rand"]mt_rand[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]25[/COLOR][COLOR= #007700]),[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()+[/COLOR][COLOR= #0000BB]365[/COLOR][COLOR= #007700]);[/COLOR] 
                    [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Location: chat_1.php"[/COLOR][COLOR= #007700]); 
                } 
            }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR] 
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<h1>You must login!</h1> 
                <form method="post"> 
                    Habbo name: <input type="text" name="habbo" id="habbo" value="nickjexx" size="45"><br> 
                    Habbo hotel: <input type="text" name="hotel" id="hotel" value="com" size="45"><br> 
                    <input type="submit" name="login" value="Continue &raquo;"> 
                </form>[/COLOR][COLOR= #007700]; 
            } 
        }[/COLOR][URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]chat-msg[/COLOR][COLOR= #007700]]){[/COLOR] 
            [COLOR= #0000BB]$msg[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]chat-msg[/COLOR][COLOR= #007700]]));[/COLOR] 
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][COLOR= #0000BB]$msg[/COLOR][COLOR= #007700]){[/COLOR] 
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]You must enter a message!<br><br><a href="chat_1.php">&laquo; Back</a>[/COLOR][COLOR= #007700]; 
            }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR] 
                [COLOR= #0000BB]$habbo2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]habbo[/COLOR][COLOR= #007700]];[/COLOR] 
                [COLOR= #0000BB]$hotel2[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]hotel[/COLOR][COLOR= #007700]];[/COLOR] 
                [COLOR= #0000BB]$margin[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]margin[/COLOR][COLOR= #007700]];[/COLOR] 
                [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO `chat` (`habbo`, `hotel`, `margin`, `message`) VALUES ($habbo2, $hotel2, $margin, $msg);"[/COLOR][COLOR= #007700]);[/COLOR] 
                [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Location: chat_1.php"[/COLOR][COLOR= #007700]); 
            } 
        }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR] 
        ?> 
            <div id="top"> 
                [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL][COLOR= #DD0000]"chat_tekst.php"[/COLOR][COLOR= #007700];[/COLOR] ?>            </div> 
            <div id="speech"> 
                <form method="post"> 
                    <input type="text" name="chat-msg" value="Enter a message..." id="chat-msg" onfocus="if (this.value==Enter a message...) this.value = ;" onblur="if (this.value==) this.value = Enter a message...;"> 
                </form> 
            </div> 
            <a href="?logout">Logout</a> 
        [COLOR= #0000BB]<?php[/COLOR] 
        [COLOR= #007700]}[/COLOR] 
        ?> 
    </div> 
</body> 
</html> 
[COLOR= #0000BB]<?php[/COLOR]  
/[COLOR= #007700]*[/COLOR] 
[URL="http://www.php.net/ob_flush"]ob_flush[/URL][COLOR= #007700]();[/COLOR] 
?>


In chat_tekst.php staat de tekst die in die mensen sturen:

[COLOR= #0000BB]<?php[/COLOR] 
[URL="http://www.php.net/require_once"]require_once[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]../config.php[/COLOR][COLOR= #007700]);[/COLOR] 
                [COLOR= #0000BB]$last10[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM chat ORDER BY `id` DESC LIMIT 10"[/COLOR][COLOR= #007700]);[/COLOR] 
                [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$last10[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]){[/COLOR] 
                    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<img src="http://habboemotion.com/usable/bubble/bubble.php?habbo=nickjexx&country=nl&text=Er zijn nog geen berichten.&format=say">[/COLOR][COLOR= #007700]; 
                }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR] 
                    [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$r[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$last10[/COLOR][COLOR= #007700])){[/COLOR] 
                        [COLOR= #0000BB]$habbo[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$r[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"habbo"[/COLOR][COLOR= #007700]];[/COLOR] 
                        [COLOR= #0000BB]$hotel[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$r[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"hotel"[/COLOR][COLOR= #007700]];[/COLOR] 
                        [COLOR= #0000BB]$margin[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$r[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"margin"[/COLOR][COLOR= #007700]];[/COLOR] 
                        [COLOR= #0000BB]$msg[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$r[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"message"[/COLOR][COLOR= #007700]];[/COLOR] 
                        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<img src="http://habboemotion.com/usable/bubble/bubble.php?habbo=[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$habbo[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]&country=[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$hotel[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]&text=[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$msg[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]&format=say" style="margin-left: [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$margin[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]px;"><br>[/COLOR][COLOR= #007700]; 
                    } 
                }[/COLOR] 
                ?>
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik zelf had dit ook.
Simpel opgelost met iframe.
Anders kan je werken met de volgende functies van jQuery :
get
post
0
Marvinn

Lid · Topicstarter

Berichten
2.609
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Maartenl schreef:
Ik zelf had dit ook.
Simpel opgelost met iframe.
Anders kan je werken met de volgende functies van jQuery :
get
post

Ik heb het met iframe. Maar chat_1.php herlaad ook als je een bericht post.

Hoe trouwens met jQuery ik heb daar geen verstand van en daarom zoek ik hulp smile
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nickjexx schreef:
Eerdere citaten tonen
Maartenl schreef:
Ik zelf had dit ook.
Simpel opgelost met iframe.
Anders kan je werken met de volgende functies van jQuery :
get
post

Ik heb het met iframe. Maar chat_1.php herlaad ook als je een bericht post.

Hoe trouwens met jQuery ik heb daar geen verstand van en daarom zoek ik hulp smile
Check chat whear systeem. Die is perfect, bericht posten en herladen met jquery wink
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat je zou kunnen doen is even controleren op javascript.
Volgens mij is er wel een functie die automatisch een veld selecteert, die zou je in de onload() van de body kunnen zetten

iets val document.getElementById(input).select, moet je maar even googlen
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Eleky schreef:
Wat je zou kunnen doen is even controleren op javascript.
Volgens mij is er wel een functie die automatisch een veld selecteert, die zou je in de onload() van de body kunnen zetten

iets val document.getElementById(input).select, moet je maar even googlen
Is het niet .focus i.p.v. .select?
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