Reputation: 273
I'm trying to get the value 3 from this link: index.php?subtopic=example&id=3
Normally I would use the $_REQUEST['id'] but I'm facing another situation here.
I got the example1.php:
<script type="text/javascript" src="js/chatbox.js"></script>
...
<div id="chat_box"></div>
And then the chatbox.js:
setInterval( function() {
$('#chat_box').load('chatbox.php');
} , 100 );
And finally the chatbox.php:
echo $_REQUEST['id'];
but I can't get the id value here :/ Please Help!!!
Upvotes: 0
Views: 111
Reputation: 273
I solved it here:
example1.php
echo "<script type='text/javascript'>
setInterval( function() {
$('#chat_box').load('chatbox.php?id=".$_GET['id']."');
} , 100 );
</script>";
echo '<div id="chat_box"></div>';
and chatbox.php:
echo $_GET['id'];
Upvotes: 0
Reputation: 65274
Basically you want to parse the id out of the URL and send it to the chat - let's do this:
<script type="text/javascript">
function getID() {
var tmp=location.href.split('?');
if (tmp.length!=2) return -2;
tmp=tmp[1].split('&');
for (i=0;i<tmp.length;i++) {
var param=tmp[i].split('=');
if (param.length!=2) continue;
if (param[0]!="id") continue;
return parseInt(param[1]);
}
return -3;
}
var chaturl='chatbox.php?id='+getID();
</script>
<script type="text/javascript" src="js/chatbox.js"></script>
...
<div id="chat_box"></div>
...
setInterval( function() {
$('#chat_box').load(chaturl);
} , 100 );
Upvotes: 2