Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-24-2012, 04:06 PM   PM User | #1
dwatson251
New to the CF scene

 
Join Date: Jan 2012
Location: Nottingham, England, United Kingdom
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
dwatson251 is an unknown quantity at this point
Real Time Chat

I've just started using AJAX to receive data from a database and quite a bit of the forums I've seen explain stuff that seem to complicated for me at the moment.

Code:
	$.ajax({  
		url: "includes/refresh.php",  
		dataType: 'html',
		success: function(data) {
			$("#messages").html(data);
			if (message_data != document.getElementById("messages").innerHTML) {
				if(document.body.className == 'blurred') {
					playSound("alert");
				}
				document.title = "[New Message]";
				setTimeout("document.title = \"Real Time Chat\"", 2000);
			}
			if(document.getElementById("loading") == "Loading... Please Wait") {
				$("#messages").html(data);
			}
		} 
	});
The above code works fine, however, how would I approach getting this to work with JSON (As I've been told that's a lot better than retrieving a bunch of messages through HTML)

Heres the PHP code of refresh.php:

Code:
	include("../includes/mysql_connect.php");
	
		$sql = mysql_query("SELECT * FROM realchat ORDER BY id DESC LIMIT 0,30");
		while($result = mysql_fetch_array($sql)) {
			if($result['id'] & 1) {
				echo "<div style='background-color:rgba(180,180,180,0.90);' class='message'>";
			}
			else { echo "<div class='message'>"; }
			if ($result['author'] == "") {
				$author = "Anon";
			} else {
				$author = $result['author'];
			}
			
			
			echo stripslashes("[".$author."]: ".$result['message']);
			echo "</div>";
		}
All help will be appreciated and if anyone could explain each new line they add/ change, that would be much more helpful, thanks!
dwatson251 is offline   Reply With Quote
Old 05-01-2012, 11:59 AM   PM User | #2
Miko001
New to the CF scene

 
Join Date: May 2012
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Miko001 is an unknown quantity at this point
I am not sure to what level you need the explanation.
But if you want my advice, choose one of the chat services out there.
They made tons of adjustments, they support ssl, they have social integration
so...you can try one of the many 123flashchat, rumbletalk, cbox....
Miko001 is offline   Reply With Quote
Users who have thanked Miko001 for this post:
Xcermide1X (05-23-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 09:19 AM.


Advertisement
Log in to turn off these ads.