JQuery Automatic Refresh

0
June 21, 2016

I tried to post something like this earlier, but it looks like it didn't work, so here it is again. I have a site that uses a separate file for a menu bar near the top. I connect it to my pages by using the PHP require function. I have a JQuery script that automatically refreshes the date and time which I use as a clock. There are values in the menu bar that change and it would be extremely convenient if they automatically refreshed like the time does. So I used the same script I did for the clock (in a huge file that I can't post here), and I used the same code to connect it to the file as I did for the clock, except with different values:

/

$(document).ready(function()

{

var refreshId = setInterval(function()

{

$('#menu').load('../inc/menu.php');

}, 5000);

});

/

And this:

/

?>

<>

/

However, when I run the script, a 0 appears at the top of the page. Other than that, it works fine. What is the problem?

Also, is there any way I can just make it refresh a certain number of times instead of constantly?

Comments See all(0)

Add comment
0
June 21, 2016

no idea what you mean by a zero appears at top of page...perhaps you have something irregular in head that is printing to page?

would be better to use setTimeout, then use a counter

var ctr=0;

var maxCtr=5;

function upDateMenu(){

setTimout(function(){

$('#menu').load('../inc/menu.php', function(){

if( ctr< maxCtr){

ctr++;

updateMenu();

}

});

},5000);

}

upDateMenu();

0
June 21, 2016

That one's not working for me. It's not doing anything. And what I mean was, after the five seconds it takes to run the script, a 0 appears on a new line by itself at the top of the page. For example, the page layout is something like:

Original

[Logo]

Version 2.0 Testing

[Clock]

Five seconds later

0

[Logo]

Version 2.0 Testing

[Clock]

It's weird. I mean the script works, but I don't want to randomly have a 0 at the top of the page all the time.

0
June 21, 2016

need to look in Firebug or other console at what is being returned in ajax, sounds like server code is adding the "0"

post a link to page that is having issues

0
June 21, 2016

Firebug didn't help. It didn't show up on it.

http://www.knightclash.com/

is the site, although the pages you're able to access don't use the menu bar with changing values. They still run the script, though, so you can see the 0 at the top.

0
June 21, 2016

Weird, it's not refreshing the values like I thought it was. It was before, but I guess I did it differently this time when I added it. I tried changing it the way I did have it before, but it's still not working. Is there just an overall better way to refresh the values in the bar? I had it so each individual value would refresh itself, but there were too many and it caused errors and down time.

0
June 21, 2016

the zero is coming right from your ajax file

http://www.knightclash.com/includes/inc-midmenu.php

why do you need to update your menu every second?

why run a timer via ajax when you can do it in the client? doesn't make a lot of sense to make 2 ajax calls every second

0
June 21, 2016

Ah, I see why it's displaying the 0 now, but I'm not sure if I can do anything about that. And I know PHP and SQL really well, but I'm not great at AJAX or really any Java. I know how the clock works, that's about it, so my first instinct was to try the menu the same way. I really have no idea what I'm doing with Java, do you have a suggestion as to how I can get my desired result more effectively?

0
June 21, 2016

I really only need the menu to refresh once every time you load a page, because when I run an SQL query and it changes a value, it doesn't display the change until after the page has already loaded. There are like 20 values that I need to do this with, though, so how can I do them all at once?

0
June 21, 2016

I don't really know what you are trying to accomplish. A google search for jquery or javascript timers should give you plenty of results

As for the 20 values...what are they for?

0
June 21, 2016

Basically I have this bar that lists a player's values for a game. You go to certain pages, these SQL values change. However, it doesn't display the change until the page reloads because it has to fully load the first time in order for the change to take place in the first place. I want the values to all reload once, or constantly if need be, so that it is less confusing. It's kind of annoying that it does that. I need a script that will load a value from an SQL database and display it. Does that help at all?

I tried Google multiple times before now. No luck, that's why I came here.

0
June 21, 2016

As another example, there is a messaging link that changes in value when you have a new message. I would like people to see when they have new messages even if they don't refresh the page for a while, you know what I mean?

0
June 21, 2016

for something like the alert box showing you can use ajax to parse data also without changing the DOM every time also. The most taxing part of running your 2 requests every second and inserting new html each time is the DOM refresh ( not page reload) when the new html is inserted.

As an example you could have a hidden element that is an alert flag. Running your ajax and testing the returned data only, vs indiscriminate and unnecessary replacement of html is a lot more efficient.

On my alert flag I have a clcik handler that would make another request to see the messages, or a hover dropdown element that gets populated with them or whatever UI desired

I'll use JSON as example

{"hasMessages": 1, "pointsChange":0,"newPointsAmount": 330}

now run ajax to pull data, but not change html unless necessary

$.getJSON( url, function(data){

if( data.hasMessages){

$('#messageFlag').text( data.hasMessages).show()

}

if(data.pointsChange){

$('#points').text( newPointsAmount);

}

});

0
June 21, 2016

I actually have no idea how to incorporate that with the PHP/SQL/HTML I use to check for messages:

$new = $db->fetch($db->query("SELECT count(*) FROM messages WHERE Recipient='" . $user['ID'] . "' AND Read=0"));

if($new[0]>0){

$newmsgs=" class=\"color\"";

}

/

/

>Messaging

Also, if I put this in a separate file without the header that connects it to the SQL database, it doesn't recognize the "$user" variable and it won't be able to fetch the count of the messages, so how do I fix that? I tried putting each variable on a separate page that each had a connection to the database, but that caused errors when more than one person was online at once. I'll try it with that code and see if it does the same thing, but I still don't know how to use that with my current PHP/SQL messaging system.

Related Questions

popup new window by use iframe

Hello, This is my jquery code (please look at below) , but the problem is when i edit or update any data on popup window, the popup it not automatic close and my master page it also not automatic ref Read More

Views

28

Votes

0

Answers

1

June 17, 2016

Refreshing Menu Bar

On my site, I have a separate file for a menu bar at the top of every page that I connect to all my pages through the PHP require function. Some of the values on this bar change while you are on the s Read More

Views

19

Votes

0

Answers

1

June 19, 2016

Automatic update of browser for all users

I was wondering what jquery function I should use in order to do the following... when an update is made to the database; update the information on ALL user's screens with the new information. Like Read More

Views

41

Votes

0

Answers

1

June 20, 2016

php multiple-field search section is too slow

Hi, My boss&#39;s website is http://www.dalamaneconomyc arhire.com / All functions work but &quot;fast quote search&quot; is too slow when customers make a search for available c Read More

Views

468

Votes

0

Answers

16

August 16, 2011

Help with the trigger function

Hey Guys, I have been reading about the trigger function.  I have tried it out on my own but it doesn't seem to be working. I took the following example from the jQuery API website and added an alert Read More

Views

39

Votes

0

Answers

4

June 19, 2016

Help keeping track of my variables

Hello, When a user login to my website his account is automatic displayed with column: name of sender, Time, Response. The last column:Response: have two buttons: accept and decline. If the user cli Read More

Views

25

Votes

0

Answers

0

June 19, 2016

This is the very first question

Hello guys! This is the first post in this site Read More

Views

2k

Votes

4

Answers

2

January 08, 2016

report values not showing up.

I have a crystal report which I pass a DataSet to using VB.NET. The report was working fine, but then I make some changes to the import query and now nothing shows up in the crystal report. Crystal do Read More

Views

1k

Votes

0

Answers

12

September 06, 2005

Event log doesn't overwrite as needed in SP4

Hello All, After upgrading from SP3 to SP4 on several Windows 2000 PRO machines everything looked fine, but from time to time applications can&#39;t write to the event log. When I try to view the appl Read More

Views

1k

Votes

0

Answers

9

May 11, 2003

"Failed to self-register XYZ.dll"

Hi there, I wrote a OLE-automation-server DLL in VB4.0. I use Installshield Express to install it as part of my program on the target computers. Now on some computers I get the message &quot;Failed to Read More

Views

8k

Votes

0

Answers

2

November 08, 1998

Please help understand these notes on image processing

Can someone please help me understand these lecture notes... On the right of the page; What does &quot;normalised by one notion of the area of a pixel&quot; mean? On the first formula for A, Is that a Read More

Views

1k

Votes

0

Answers

3

February 05, 2009

Can someone please explain this paragram on the chain rule in image processing

Please see the screenshot, How is 3133030 got from 10103322? Read More

Views

1k

Votes

0

Answers

1

January 05, 2009

AD on 2003

We have created an AD Domain on Windows 2000 Server with no problems. We just created an AD Domain on Windows 2003 and we&#39;re getting some weird problems. Both of these domains are behind firewalls Read More

Views

1k

Votes

0

Answers

15

May 11, 2003

ADDT ASP Upload Error " Type mismatch: 'tNG_isFileInsideBaseFolder' "

I am trying to create a simple insert record and upload image function on an ASP page built using Adobe Dreamweaver Developer Toolkit. I have done this many times before with no problem, however, i ha Read More

Views

1k

Votes

0

Answers

0

November 02, 2008

MYSQL Select query with custom ORDER BY

Hi, is it possible to customize the order of the returned rows in mysql? Example: I have a Table with a column &quot;name&quot;, now I want to have all entries ordered by name, but I want the entries Read More

Views

1k

Votes

0

Answers

5

July 02, 2010

Folder Redirection in Server 2003

We have a Windows Server 2003 Standard Ed. Is there a way to redirect the users my documents to a folder that has already been created on the server? Read More

Views

1k

Votes

0

Answers

2

July 05, 2007

Partiton magic  version 8.0 having error 1523 while executing batch

I followed the partition magic 8.0 wizard to partition my hard disk while rebooting &#160;I came across this problem &#160;&quot;error 1523 while executing batch&quot; What can I do to solve this prob Read More

Views

1k

Votes

0

Answers

2

May 11, 2003

Please explain this paragraph in image processing (screenshot attached)

Two questions; How is the equation (10.1-15) formed? &quot;are isotropic for rotation increments of 90 degrees and 45 degrees respectively&quot; What does this mean Read More

Views

1k

Votes

0

Answers

7

January 05, 2009

xp_cmdshell with net use

Hi, when I use &#39;net use \192.168.0.1\c$ password /user:username&#39; at the command prompt, it works fine. &#160;But if i try to use it in sql with &quot; exec master..xp_cmdshell &#39;net use \19 Read More

Views

978

Votes

0

Answers

5

April 11, 2003

hp ux11

i have a hp ux11 server. and i edited the /etc/resolv.conf to use my win2003 server dns server. That went fine, however, I would like to go the other way and add an entry on my win2003 dns to resolve Read More

Views

610

Votes

0

Answers

3

October 12, 2009