homepage Welcome to WebmasterWorld Guest from 54.204.249.184
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Ajax Chatting Routine Not Working
calabar




msg:4663866
 4:10 pm on Apr 17, 2014 (gmt 0)

IT IS NOT WORKING , GOT KNOW ERRORS


<HTML>
<HEAD>
<STYLE>
#CHATBOX{
position : absolute;
top : 900px;
left : 2%;
width : 100%;

}

</STYLE>

<script src="//code.jquery.com/jquery-1.10.2.js"></script>

<SCRIPT>
$(document).ready (function(){
var LLAST = 0;

function CHATTING(){
DATACOUNT = { "COUNTER" : LLAST };
$.ajax({
type : "POST",
url : "http://localhost/AJAXPHP/JQUERY/CHATTING/CHATTING.PHP",
data : {"MYDATA" : JSON.stringify( DATACOUNT )},
dataType : "json",
success : function(MESSAGES){
LLAST = LLAST + MESSAGES.Length;
var ULNODE = $("<UL>")
for ( COUNTER= 0;COUNTER < MESSAGES.Length; COUNTER++ ){
NAME = MESSAGES[COUNTER].NAME;
MESSAGE= MESSAGES[COUNTER].MESSAGE;
ULNODE.Append ( "<LI>" + NAME + ":" + MESSAGE + "</LI>" )
}
$("#CHATBOX").append ( ULNODE );
}
});


}
window.setInterval( CHATTING, 5000 );



});

<SCRIPT>

<DIV ID="CHATBOX">


</DIV>

######################################################
######################################################
CHATTING.PHP


<?php

$CON = mysql_connect( "localhost","root","");
mysql_select_db( "AJAXDBF", $CON );
$DATA =json_decode ( $_POST['MYDATA'],true ) ;
$LAST = $DATA["COUNTER"];
$SQLMESSAGE = " SELECT * FROM MESSAGES ";
$SQLMESSAGE.= " WHERE MESSAGEID > " . $LAST;
$FMESSAGE = mysql_query($SQLMESSAGE , $CON );
$MESSAGES = array();
while ( $ROW = mysql_fetch_array( $FMESSAGE)){
$ROW_ARRAY = array(
'NAME' => $ROW["NAME"],
'MESSAGE' => $ROW["MESSAGE"]
);
array_push( $MESSAGES, $ROW_ARRAY );

}
echo ( json_encode ( $MESSAGES ));
?>

 

calabar




msg:4663870
 4:17 pm on Apr 17, 2014 (gmt 0)

IT IS NOT CALLING CHATTING.PHP REPEATEDLY. Sorry for
shouting.

calabar




msg:4664152
 1:38 pm on Apr 18, 2014 (gmt 0)

The AJAX chat Routine is now calling CHATTING.PHP
but the JSON DATA returned is occurring two times

CHATTING.PHP

<?php

$CON = mysql_connect( "localhost","root","");
mysql_select_db( "AJAXDBF", $CON );
$DATA =json_decode ( $_POST['MYDATA'],true ) ;
$LAST = $DATA["COUNTER"];
$SQLMESSAGE = " SELECT * FROM MESSAGE ";
$SQLMESSAGE.= " WHERE MESSAGEID > " . $LAST;
$FMESSAGE = mysql_query($SQLMESSAGE , $CON );
$MESSAGES = array();
while ( $ROW = mysql_fetch_array( $FMESSAGE)){
$ROW_ARRAY = array(
'NAME' => $ROW["NAME"],
'MESSAGE' => $ROW["MESSAGE"]
);
array_push( $MESSAGES, $ROW_ARRAY );

}
echo ( json_encode ( $MESSAGES ));
?>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved