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-22-2010, 08:02 PM   PM User | #16
matthewst
New Coder

 
Join Date: Nov 2006
Posts: 48
Thanks: 3
Thanked 1 Time in 1 Post
matthewst is an unknown quantity at this point
Okay, I wasn't as close as I thought. Js is still just echoing whatever php is outputting.

Code:
function handleJoblog() {
  if(httpjob.readyState == 4) {
    var response = httpjob.responseText;
	if(response=="Update! ") {
    document.getElementById('bar').innerHTML = response;
	document.getElementById('bar').style.color = "red"
	}
	if(response!="Update! ") {
    document.getElementById('bar').innerHTML = response;
	document.getElementById('bar').style.color = "yellow"
	}
  }
}
The above code outputs in yellow whether there is new data or not.

Here is the php:
Code:
$total_job_log_entries = ceil(mysql_num_rows(mysql_query("SELECT id FROM job_log WHERE id > '1'")));
if ($total_job_log_entries != $jle_old){
$response = "Update! ";
echo $response;
echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
}else{
echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
}
matthewst is offline   Reply With Quote
Old 03-22-2010, 08:14 PM   PM User | #17
matthewst
New Coder

 
Join Date: Nov 2006
Posts: 48
Thanks: 3
Thanked 1 Time in 1 Post
matthewst is an unknown quantity at this point
I couldn't get this to work either.
Code:
  if(httpjob.readyState == 4) {
    var response = httpjob.responseText;
	if(newdata == yes) {
    document.getElementById('bar').innerHTML = response;
	document.getElementById('bar').style.color = "red"
	}
	if(response!="Update! ") {
    document.getElementById('bar').innerHTML = response;
	document.getElementById('bar').style.color = "yellow"
	}

Code:
$total_job_log_entries = ceil(mysql_num_rows(mysql_query("SELECT id FROM job_log WHERE id > '1'")));
if ($total_job_log_entries != $jle_old){
?>
<script type="text/javascript">
var newdata=yes;
</script>
<?php
//$response = "Update! ";
//echo $response;
echo $response . "Total number of job log entries: " . $total_job_log_entries . "<br>";
}else{
echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
}
$HTTP_SESSION_VARS["jle_old"] = $total_job_log_entries;
matthewst is offline   Reply With Quote
Old 03-22-2010, 09:46 PM   PM User | #18
tfit
New Coder

 
Join Date: May 2008
Posts: 80
Thanks: 3
Thanked 3 Times in 3 Posts
tfit is an unknown quantity at this point
Netscape

Matthew you're completely screwing your code. that javascript line doesn't doesn't help much and still trying clientside evualation .
where comes this newdata from?
Assuming the server returns update or noupdate. we can than return to the switch statement
switch(response) {
case update:
document.getElementById('bar').innerHTML = response;
document.getElementById('bar').style.color = "red"
break;
default :
document.getElementById('bar').innerHTML = response;
document.getElementById('bar').style.color = "yellow"
}
when done that you can return your whole string and do a substring search for noupdate

Last edited by tfit; 03-22-2010 at 09:53 PM.. Reason: added information
tfit is offline   Reply With Quote
Old 03-23-2010, 01:13 AM   PM User | #19
matthewst
New Coder

 
Join Date: Nov 2006
Posts: 48
Thanks: 3
Thanked 1 Time in 1 Post
matthewst is an unknown quantity at this point
That's the problem. PHP will output either "blah 123" or "Update! blah 124". Js is simply echoing what php is outputing. I don't want to include the word "Update".

If it were all php I would do this:

Code:
session_start();

//job log entries
$total_job_log_entries = '0';
$total_job_log_entries = ceil(mysql_num_rows(mysql_query("SELECT id FROM job_log WHERE id > '1'")));
if ($total_job_log_entries != $jle_old){
//new data
echo "<font color='red'>Total number of job log entries: " . $total_job_log_entries . "</font><br>";
}else{
//same old data
echo "<font color='yellow'>Total number of job log entries: " . $total_job_log_entries . "</font><br>";
}
$HTTP_SESSION_VARS["jle_old"] = $total_job_log_entries;
mysql_close();
All I need is a way to tell Js I have new data so I can make the background for that table cell flash or briefly change color or something.
matthewst is offline   Reply With Quote
Old 03-23-2010, 02:07 AM   PM User | #20
matthewst
New Coder

 
Join Date: Nov 2006
Posts: 48
Thanks: 3
Thanked 1 Time in 1 Post
matthewst is an unknown quantity at this point
GOT IT!!!!!!
Added this function on the client side:
Code:
function blinkIt() {
 if (!document.all) return;
 else {
   for(i=0;i<document.all.tags('blink').length;i++){
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   }
 }
}
And this on the server side:
Code:
if ($total_job_log_entries != $jle_old){
$response = "Update! ";
echo "<blink>Total number of job log entries: " . $total_job_log_entries . "</blink><br>";
}else{
echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
}
matthewst is offline   Reply With Quote
Old 03-23-2010, 07:52 AM   PM User | #21
tfit
New Coder

 
Join Date: May 2008
Posts: 80
Thanks: 3
Thanked 3 Times in 3 Posts
tfit is an unknown quantity at this point
Quote:
Originally Posted by matthewst View Post
GOT IT!!!!!!
Added this function on the client side:
Code:
function blinkIt() {
 if (!document.all) return;
 else {
   for(i=0;i<document.all.tags('blink').length;i++){
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   }
 }
}
And this on the server side:
Code:
if ($total_job_log_entries != $jle_old){
$response = "Update! ";
echo "<blink>Total number of job log entries: " . $total_job_log_entries . "</blink><br>";
}else{
echo "Total number of job log entries: " . $total_job_log_entries . "<br>";
}
you're introducing different viewpoints at times , but i'm glad you got it working
tfit is offline   Reply With Quote
Old 03-23-2010, 01:07 PM   PM User | #22
matthewst
New Coder

 
Join Date: Nov 2006
Posts: 48
Thanks: 3
Thanked 1 Time in 1 Post
matthewst is an unknown quantity at this point
Yeah, I'm still learning Js. Thanks for the help.



How do I mark this resolved?

Last edited by matthewst; 03-23-2010 at 01:11 PM..
matthewst is offline   Reply With Quote
Old 03-23-2010, 01:34 PM   PM User | #23
tfit
New Coder

 
Join Date: May 2008
Posts: 80
Thanks: 3
Thanked 3 Times in 3 Posts
tfit is an unknown quantity at this point
I have to search for that from time to time too Anyway go to your first post, edit, advanced, title and there you can change status

Last edited by tfit; 03-23-2010 at 01:39 PM..
tfit is offline   Reply With Quote
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 12:56 AM.


Advertisement
Log in to turn off these ads.