Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to make Ajax to refresh part page
Old 05-07-2008, 12:30 PM How to make Ajax to refresh part page
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Okay

So i have a shoutbox script and i want the chat to automatically refresh every X amount of time.

How can this be done?


TP for working answer
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 05-07-2008, 12:48 PM Re: How to make Ajax to refresh part page
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
http://aleembawany.com/2005/09/01/aj...tant-tutorial/

You would need to add a timer onto it. Here is another example, with a timer:

http://ajaxpatterns.org/Periodic_Refresh

Last edited by VirtuosiMedia; 05-07-2008 at 12:49 PM..
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-07-2008, 12:52 PM Re: How to make Ajax to refresh part page
Average Talker

Posts: 15
Name: Mark
Trades: 0
You can also use a meta refresh on the actual display page inside your chat script.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Datingsoftware is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 12:59 PM Re: How to make Ajax to refresh part page
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
that wont do, it needs to be ajax so it only refreshes the part i want.

And is much better lol
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-07-2008, 01:04 PM Re: How to make Ajax to refresh part page
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
This page is for AJAX chat, but I would imagine that one of them would give you what you're looking for: http://ajaxpatterns.org/Examples#Chat

Or, if you're open to it, you can have a Skype chatroom as well. I think it'll open up in the Skype program, but you could also combine it with an affiliate link so that if they don't have Skype, you could earn money. Plus it saves you development time and bandwidth. The Skype site is horrid to navigate, but I think I found what you need to know here: http://skype.com/help/guides/publicchat_create.html

Last edited by VirtuosiMedia; 05-07-2008 at 01:16 PM..
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-07-2008, 01:18 PM Re: How to make Ajax to refresh part page
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Nah, i will (eventually) develop this into a full shoutbox service...

Just need some Ajax to reget posts from the db.

Found this on one of the pages would it do it?
Code:
<script type="text/javascript">
var page = "online.php";
function ajax(url,target) {
  // native XMLHttpRequest object
  document.getElementById(target).innerHTML = 'Loading...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = function() {ajaxDone(target);};
    req.open("GET", url, true);
    req.send(null);
    // IE/Windows ActiveX version
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLDOM");
    if (req) {
      req.onreadystatechange = function() {ajaxDone(target);};
      req.open("GET", url, true);
      req.send(null);
    }
  }
  setTimeout("ajax(page,'scriptoutput')", 5000);
}

function ajaxDone(target) {
  // only if req is "loaded"
  if (req.readyState == 4) {
    // only if "OK"
    if (req.status == 200 || req.status == 304) {
      results = req.responseText;
      document.getElementById(target).innerHTML = results;
    } else {
      document.getElementById(target).innerHTML="ajax error:\n" +
      req.statusText;
    }
  }
}
</script>
This is the PHP code:

PHP Code:

echo '<div id="right_side">';
if (!isset(
$_GET['pagenum']))

$pagenum 1

else { 
$pagenum $_GET['pagenum'];
}
$result mysql_query("SELECT * FROM messages WHERE shoutbox_id='$shoutbox_id' ORDER BY datetime DESC") or die("ERROR:".mysql_error());

$rows mysql_num_rows($result); 
//This is the number of results displayed per page 
$page_rows $shoutbox['post_per_page']; 
//This tells us the page number of our last page 
$last ceil($rows/$page_rows); 
//this makes sure the page number isn't below one, or more than our maximum pages 
if ($pagenum 1

$pagenum 1

elseif (
$pagenum $last

$pagenum $last

//This sets the range to display in our query 
$max 'ORDER BY datetime DESC LIMIT ' .($pagenum 1) * $page_rows .',' .$page_rows;
//This is your query again, the same one... the only difference is we add $max into it
$messages_res mysql_query("SELECT * FROM messages WHERE shoutbox_id='$shoutbox_id$max") or die("ERROR:".mysql_error());
while(
$msg mysql_fetch_array($messages_res))
{
$msg['datetime'] = strtotime($msg['datetime']);
$msg['datetime'] = date('d/m/Y H:i'$msg['datetime']);
echo 
'<div class="message">';
echo 
'<span class="msg_user">'.wordwrap($msg['user'],12"<br />\n"true).':</span><br />';
echo 
wordwrap($msg['msg'], 18"<br />\n"true).'<br />
<span class="smltxt">'
.$msg['datetime'].'</span>
<br />
</div>'
;
}
echo 
'</div>';
/* Pagination links */
echo '<span id="links">';
if (
$pagenum != && $pagenum != 0
{
$previous $pagenum-1;
echo 
" <a href='{$_SERVER['PHP_SELF']}?sb=".$_GET['sb']."&pagenum=$previous'>".$shoutbox['prev_name']."</a> ";

for(
$i 1$i <= $last$i++)
{
echo 
" <a href='{$_SERVER['PHP_SELF']}?sb=".$_GET['sb']."&pagenum=$i'> $i</a> ";
}
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum != $last
{
$next $pagenum+1;
echo 
" <a href='{$_SERVER['PHP_SELF']}?sb=".$_GET['sb']."&pagenum=$next'>".$shoutbox['next_name']."</a> ";
}
echo 
'</span>'
(this is just the part which needs refreshing.)

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-07-2008, 01:29 PM Re: How to make Ajax to refresh part page
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
I think it should work, but you'll have to set your url and target parameters. You may also want to experiment with POST if GET isn't doing it for you.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-07-2008, 04:45 PM Re: How to make Ajax to refresh part page
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Okay im really no good with Javascript/Ajax can someone please do this for me will give TP
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 05-07-2008, 06:03 PM Re: How to make Ajax to refresh part page
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
Okay im really no good with Javascript/Ajax can someone please do this for me will give TP
No idea, but maybe post in the Javascript forum if you don't get any help here
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to make Ajax to refresh part page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.85833 seconds with 12 queries