•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,971 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,174 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 927 | Replies: 4
![]() |
Is there any way to count users in my chatroom and display whos chatting using javascript or ajax? code in php below has issues, but this is what it should do.
I was not able to use php on my website software directly so I was hoping to to remotely host this code and display the data by using an iframe sourced from the remote file, however various issues arose.
could I do the same thing with ajax or javascript?
<?php
$chatnames = file('http://client11.addonchat.com/scwho.pl?id=292747&plain=1');
$indx = count($chatnames);
$indxcom = $indx - 1;
if ($indx == 0) {
echo "<b>No one is in the chat room at the moment</b>";
}
else{
echo "<b>People Chatting:</b> ";
for($i = 0; $i < $indx; $i++) {
$name = explode(' ', $chatnames[$i], 2);
echo " $name[0]";
if ($i < $indxcom) {
echo ", ";
}
}
}
?>
I was not able to use php on my website software directly so I was hoping to to remotely host this code and display the data by using an iframe sourced from the remote file, however various issues arose.
could I do the same thing with ajax or javascript?
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
I found A few Errors But Still no output, Help?
<?
Header("content-type: application/x-javascript");
$chatnames = file('http://client11.addonchat.com/scwho.pl?id=292747&plain=1');
$indx = count($chatnames);
$indxcom = $indx - 1;
if ($indx == 0){
echo "document.write(\"No one is in the chat room at the
moment"\)";
}
else{
echo "document.write(\"<b>Members Chatting:</b>"\)";
for($i = 0; $i < $indx; $i++) {
$name = explode(' ', $chatnames[$i], 2);
echo "document.write(\"$name[0]"\)";
if ($i < $indxcom) {
echo "document.write(\","\)";
}
}
}
?>
Last edited by Inny : Mar 13th, 2008 at 2:32 pm.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
using ajax to call a php fuction:
put this where you want resutls:
include this ajax library in the page you want the results to display on.html Syntax (Toggle Plain Text)
<div id="results" style="display:inline; width:100px; height:20px;"></div>http://www.codeproject.com/KB/ajax/SAL/sal_src.zipcreate php page with your function in it and do this:html Syntax (Toggle Plain Text)
<script type="javascript" src="path_to_ajax_lib"></script>
insert this into your page after the div:php Syntax (Toggle Plain Text)
<?php function online(){ //i write this asumming that the script you are getting contents from is correct //and is returning correct input in the form of an array $online = file('http://client11.addonchat.com/scwho.pl?id=292747&plain=1'); return $online; } if($_GET['results']=='membernames'){ $users = online(); foreach($users as $u){ echo $u; } ?>
javascript Syntax (Toggle Plain Text)
SetInnerHTMLFromAjaxResponse('your_php_page.php?results=membernames', 'results');
Last edited by hunkychop : Mar 13th, 2008 at 4:58 pm. Reason: fix code tags
toast
•
•
•
•
using ajax to call a php fuction:put this where you want resutls:
include this ajax library in the page you want the results to display on.html Syntax (Toggle Plain Text)
<div id="results" style="display:inline; width:100px; height:20px;"></div>http://www.codeproject.com/KB/ajax/SAL/sal_src.zipcreate php page with your function in it and do this:html Syntax (Toggle Plain Text)
<script type="javascript" src="path_to_ajax_lib"></script>
insert this into your page after the div:php Syntax (Toggle Plain Text)
<?php function online(){ //i write this asumming that the script you are getting contents from is correct //and is returning correct input in the form of an array $online = file('http://client11.addonchat.com/scwho.pl?id=292747&plain=1'); return $online; } if($_GET['results']=='membernames'){ $users = online(); foreach($users as $u){ echo $u; } ?>
javascript Syntax (Toggle Plain Text)
SetInnerHTMLFromAjaxResponse('your_php_page.php?results=membernames', 'results');
The above expects HTML output from a page, not JavaScript output as given in the PHP function.
The original post also mentions having the PHP file on a different domain. AJAX via the XMLHttpRequest object requires that the files be on the same domain. (At least untill cross domain XMLHttpRequest becomes implemented in all browsers as per the W3C specifications)
A workable solution would have be to use "JavaScript Remoting". You can include a JavaScript file after the page has loaded.
Simple example being:
document.write('<script type="text/javascript" src="http://example.com/your/remote/file.php"></script>');The src attribute would be your remote PHP file. It would have to return a JavaScript function call, as it currently does in your PHP script.
PS: you can also use "Iframe Remoting" which is similar but uses Iframes instead. That is limited to JavaScript function calls also because of the "same origin policy" in effect in XMLHttpRequest also.
Last edited by digital-ether : Mar 15th, 2008 at 1:56 am.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Inserting dynamic values into Javascript variables (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Substitute for clip Property
- Next Thread: LogicWeb Javascript


Linear Mode