Hallo allemaal,
Ik was bezig met AJAX, alleen nu wil ik dat als mensen op een link klikken, dat nieuwsreact.php opent. En dat die nieuwsreact weet dat het om id=1 gaat.
Ik had het volgende:
Het AJAX gedeelte:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function create_http_object()
{
var ActiveXTypes = [
"Microsoft.XMLHTTP",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP"
];
for( var i = 0; i < ActiveXTypes.length; i++ )
{
try
{
return new ActiveXObject( ActiveXTypes[i] );
}
catch( e )
{ }
}
try
{
return new XMLHttpRequest();
}
catch( e )
{ }
return false;
}
function make_request(url, callback_function, http_method, post_values, return_xml)
{
http = create_http_object();
if(!http)
{
alert('Je browser ondersteunt deze feature niet.');
return false;
}
http.onreadystatechange = function()
{
if(http.readyState == 4)
{
if(http.status == 200)
{
if(callback_function)
{
if(return_xml)
{
eval(callback_function + '(http.responseXML)');
}
else
{
eval(callback_function + '(http.responseText)');
}
}
}
else
{
alert('Error! (' + http.status + ')');
}
}
}
if(!post_values)
{
post_values = null;
}
if(!http_method)
{
http_method = "GET";
}
http.open(http_method, url, true);
if(http_method == "POST")
{
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
http.send(post_values);
}
function handle_response(result)
{
document.getElementById('result_div').innerHTML = result;
}
De link
1
2
3
4
5
<?php
echo '<a href="index.php/nieuws/'.$_GET['id'].'/" onClick="make_request(\'nieuwsreact.php?id='.$_GET['id'].'/\', \'handle_response\');return false;" border="0">';
?>
de url:
1
http://10.105.1.202/Thomaz.eu.tc/index.php/nieuws/berichten/1
En tenslotte de nieuwsreact.php:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
session_start();
include ("config.php");
include_once ("global.php");
echo '
<table width="599" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1" background="png/pb/punt.png"></td>
<td align="center"><table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left">';
if (!isset($_SESSION['status_id']) or $_SESSION['status_id'] < 1)
{
echo "<b><span class="Rood">- Je bent niet ingelogd, log je eerst in om te kunnen reageren</span></b>";
}
else
{
regels();
if ($_SERVER['REQUEST_METHOD'] != "POST")
{
$flood2 = $_SESSION['flood'];
$datum = date("d-m-Y H:i:s");
if ($flood2 > $datum)
{
echo "<span class="Rood">- Je hebt net een bericht gepost, je moet even wachten voordat je weer kunt reageren.</span>";
}
else
{
$querys = "SELECT * FROM nieuws WHERE reactie='nee' && id='".safe(is_numeric($_GET['id']))."'";
$results = mysql_query($querys) or die (mysql_error());
$totaal = mysql_num_rows($results);
if ($totaal < 1)
{
echo "<span class="Rood"><b>- Ongeldige actie </b></span>";
}
else
{
$sql = mysql_fetch_assoc($results);
echo "Lees voor het posten eerste de <a href="".$vsite."index.php/regels">regels</a> eens door.";
echo '<form id="form" name="bericht" method="post" action=""><b>Titel:</b><br />
<input type="text" name="titel" value="Re: '; echo $sql['titel']; echo '" size="55" class="tekstvak" /><br />
<br />
<b>Bericht:</b><br />
'; ?>
<img src="images/icoons/text_bold.png" alt="" title="Dikgedrukt" style="cursor:pointer;" onclick="javascript:bb('[b]','[/b]')" border="1" class="tekstvak2" />
<img src="images/icoons/text_italic.png" alt="" title="Schuine tekst" style="cursor:pointer;" onclick="javascript:bb('[i]','[/i]')" border="1" class="tekstvak2" />
<img src="images/icoons/text_underline.png" alt="" title="Onderstreept" style="cursor:pointer;" onclick="javascript:bb('[u]','[/u]')" border="1" class="tekstvak2" />
<img src="images/icoons/text_strikethrough.png" alt="" title="Doorstreept" style="cursor:pointer;" onclick="javascript:bb('[s]','[/s]')" border="1" class="tekstvak2" />
<img src="images/icoons/color_wheel.png" alt="" title="Kleur" style="cursor:pointer;" onclick="javascript:bb('[color=green]','[/color]')" border="1" class="tekstvak2" />
<img src="images/icoons/text_smallcaps.png" alt="" title="Text grootte" style="cursor:pointer;" onclick="javascript:bb('[size=4]','[/size]')" border="1" class="tekstvak2" />
<img src="images/icoons/text_align_justify.png" alt="" title="Uitlijnen" style="cursor:pointer;" onclick="javascript:bb('[align=left]','[/align]')" border="1" class="tekstvak2" />
<img src="images/icoons/image.png" alt="" title="Afbeelding toevoegen" style="cursor:pointer;" onclick="javascript:bb('[img]','[/img]')" border="1" class="tekstvak2" />
<img src="images/icoons/script_code.png" alt="" title="Code" style="cursor:pointer;" onclick="javascript:bb('[code*]','[**/code]')" border="1" class="tekstvak2" />
<img src="images/icoons/page_white_swoosh.png" alt="" title="Quote" style="cursor:pointer;" onclick="javascript:bb('[quote]','[/quote]')" border="1" class="tekstvak2" />
<img src="images/icoons/link.png" alt="" title="Link" style="cursor:pointer;" onclick="javascript:bb('[url]','[/url]')" border="1" class="tekstvak2" />
<img src="images/icoons/email.png" alt="" title="Email" style="cursor:pointer;" onclick="javascript:bb('[email]','[/email]')" border="1" class="tekstvak2" />
<img src="images/icoons/text_superscript.png" alt="" title="Superscript" style="cursor:pointer;" onclick="javascript:bb('[sup]','[/sup]')" border="1" class="tekstvak2" />
<img src="images/icoons/text_subscript.png" alt="" title="Subscript" style="cursor:pointer;" onclick="javascript:bb('[sub]','[/sub]')" border="1" class="tekstvak2" />
<img src="images/icoons/text_list_bullets.png" alt="" title="Subscript" style="cursor:pointer;" onClick="javascript:bb('[list]\n[*]','\n[/list]')" border="1" class="tekstvak2" />
<?php echo '
<textarea name="bericht" cols="55" rows="15" class="tekstvak">'; echo $bericht; echo '</textarea><br />';
echo "
<img src="images/smile/smile.png" width="17" height"17" style="cursor:pointer;" padding="0" onclick="javascript:bb(':)')" />
<img src="images/smile/bigsmile.png" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb(':D')" />
<img src="images/smile/wink.gif" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb(';)')" />
<img src="images/smile/tong.gif" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb(':P')" />
<img src="images/smile/verbaasd.png" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb(':O')" />
<img src="images/smile/boos.png" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb(':(')" />
<img src="images/smile/raar.png" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb(':S')" />
<img src="images/smile/triest.png" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb(':|')" />
<img src="images/smile/kwaad.png" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb(':@')" />
<img src="images/smile/zonnebril.png" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb('(H)')" />
<img src="images/smile/bril.png" width="17" height"17" style="cursor:pointer;" onclick="javascript:bb('8)')" />
";
echo '
<br /> <input type="submit" name="Submit" value="Verzend" class="tekstvak" />
<table width="599" height="3" border="0" cellpadding="0" cellspacing="0" background="images/Balk_onder.PNG">
<tr>
<td></td>
</tr>
</table>';
}
}
}
else
{
if (empty($_POST['bericht']))
{
echo "<span class="Rood"><b>- Het bericht veld is leeg, typ eerst een bericht voordat je op verzenden drukt.</b></span>";
}
else
{
$flood2 = $_SESSION['flood'];
$datum = date("d-m-Y H:i:s");
if ($flood2 > $datum)
{
echo "<span class="Rood">- Je hebt net een bericht gepost, je moet even wachten voordat je weer kunt reageren.</span>";
}
else
{
$datum = date("d-m-Y").", om ".date("H:i");
$querys = "SELECT * FROM nieuws WHERE reactie='nee' && id='".safe(is_numeric($_GET['id']))."'";
$results = mysql_query($querys) or die (mysql_error());
$sql = mysql_fetch_assoc($results);
@mysql_query("INSERT INTO nieuws (id,cat,titel,bericht,reactie,datum,user,nieuws_id) VALUES ('','".$sql['cat']."','".safe($_POST['titel'])."','".safe($_POST['bericht'])."', 'ja', '".$datum."', '".$_SESSION['naam']."', '".safe($_GET['id'])."')") or die("Mysql error op regel ".__LINE__." : ".mysql_error());
echo "<b>Je reactie is succesvol geplaatst!</b><br />Je wordt over 3 seconden doorgestuurd naar de reacties, als je niet kunt wachten klik dan <a href="".$vsite."index.php/nieuws/berichten/".$_GET['id']."">hier</a>.<META HTTP-EQUIV='refresh' CONTENT='3; URL=".$vsite."index.php/nieuws/berichten/".$_GET['id']."'>";
$_SESSION['flood'] = date("d-m-Y H:i:s",time()+15);
}
}
}
}
echo '</td>
</tr>
</table>
</td>
<td width="1" background="png/pb/punt.png"></td>
</tr>
</table>
<table width="599" border="0" cellspacing="0" cellpadding="0">
<tr>
<td background="png/pb/punt.png" height="1"></td>
</tr>
</table>';
?>
De url staat duidelijk in ?id=1 (Alleen gaat het met slashes.)
Alleen de nieuwsreact kan de ?id=1 niet uit de url halen. Weet iemand wat ik fout doe?
Mvg. Thomas
Opgelost!
[Laatst bewerkt door Thomaz op zondag 11 maart 2007, om 13:36]