Hello , i got this code that works great , now i want to have it refresh every 4 seconds , where can i put the timer to do that?
i realy need help!!
thanx!! 29 8108
Though I have an idea how you did, can you post how you solved it? It may help someone else who comes across this thread looking for a solution to a similar problem.
The true :) ,it did solve one thing to refresh the content ,but it didnt solve the all thing i needed,
i just put the setTimeout in the right position ,and it did refresh , but it was doing refresh and bring me all the time to the first page!! (im using it with pagination from mysql database)
what i did: - function showPage(str) {
-
//Function that gets called
-
//Currently we only call one other sub, but this could change
-
showStates(str)
-
setTimeout('showPage("1")', 4000);
-
}
-
i hope it will help some one!!
and maybe some one can help me to solve it to stay in the next page with refreshing also!!
That's because you're always calling it with "1". Use an integer and update it each time you make the call. Note that you can use setInterval in place of setTimeout.
this is the 2 files im using ,maybe some one can take a look at them and tell me what im doing wrong! or what to do!!
the first file is the ajax script to call the second file ,the second file is calling the ddatabase for the records ,my problem is with the pagination ,if i put setTimeout to refresh the page it's returning back to the first page after the amount of time i put in the setTime out!!
what can i do to keep refreshing the current page im in to!!
thanx
When you mention "current page", is it a paginated view, e.g. the URL has a page number as a parameter?
Note that your onload is incorrect. It should be something like: - window.onload = function() {
-
setInterval(showPage,4000);
-
}
You could have the page number as a global variable which can be incremented in showPage.
it is pagination ,i put the onload you told me ,but when im going to page No 2 for example ,it's jumpijng back to page 1 ,after 4 seconds!
im not so good in php and javascript :)
i try so many combinations and it keep jumping to page one!!
thanx for youe help!
OK, on the first page when you're on page 2, what's the full page URL including after the ?
this is the problem:
window.onload = showPage("1");
the 1 is a connection for the +str that is reloading the page no 1
when it's like that window.onload = showPage("1"); ,i can navigate with the links ,but i want to have it refresh also if there is new data!!
this the url with all: for content
var url="getuser.php?bid_id=<?=$bid_id;?>"
url=url+"&p="+str
url=url+"&t=con"
url=url+"&sid="+Math.random()
this the url with all: for navigation
var url="getuser.php?bid_id=<?=$bid_id;?>"
url=url+"&p="+str
url=url+"&t=nav"
url=url+"&sid="+Math.random()
i removed the onload you wrote me , so now its without it
this is the link for example how it is now ,without settimeout or iterval http://www.bonker.co.il/product_detail.php?bid_id=205
In your link, there's no page number, so how would it be reflected if you were on page 2? In other words, how do you get onto the second page? Is there a link on the page, or do you want this to happen automatically after 4 seconds?
look at the bottom of the results ,its there
5,4,3,2,1 in red
i want the current page im in to be auto refresh after 4 seconds.
Oh, I see. These links are to showPage with the correct page number.
What you can do is add a global variable, pageno which is set to 1 initially. Then in the links, set this variable to the corresponding number. In the meantime, showPage will be called every 4 seconds using setInterval.
if i knew how to do it ,it was good then !
im not this good in JS or PHP :)
:(
thanx alot!!
You only need to make a few changes.
1. Change window.onload to what I posted earlier.
2. Change showPage() to accept 0 parameters: function showPage() {
3. Add a global variable pageno which will be used in place of that parameter:
4. Replace str in showPage() with pageno.
5. Change the links to set pageno instead of calling showPage: - <a href="#" onclick="pageno = 2; return false;">2</a>
thanx alot man!! , when i get home im going to try it!!!!
thanks!!!
i try everything and i cannot figure it out how to do it :(
any help will be appreciated !!
thanx
I can't see any changes in the page linked to earlier. What changes did you make? Have you got a link with the changes?
i did so meny combinations!
i dont know how to change the var from the tha JS.
the JS is calling the php file with the str that is equal to 1
the navigation numbers are in the php file so i think i cannot change the links!
if i could chang the JS from the php file to change the str to different number then i think it will be fine!
but i dont know how to cahnge the JS from the php file!!
here are both of the files!
the java script
i dont know how to change the var from the tha JS.
the JS is calling the php file with the str that is equal to 1
the navigation numbers are in the php file so i think i cannot change the links!
if i could chang the JS from the php file to change the str to different number then i think it will be fine!
You don't need to change the variable from PHP. You need to adjust your JavaScript. You can also change the links too.
First things first, add a variable that will hold the current page number (point no. 3). Then use that in place of str, i.e. no need to pass a parameter to showPage(). Worry about the links later.
ok ,this is what i did and it is working for the corrent page!
i changed all the str with 'pageno' ,the pageno = 1
if i change the pageno to 2 then it will stay in page 2 and do the settimeout
here is the code for the moment: - var pageno = 1;
-
function showPage(pageno) {
-
//Function that gets called
-
//Currently we only call one other sub, but this could change
-
showStates(pageno)
-
-
}
-
-
-
function showStates(pageno) {
-
//This sub will populate a table with all the states and get the
-
//pagination built
-
-
-
//Make the AJAX connection for both the navigation and content
-
xmlHttp=GetXmlHttpObject()
-
xmlHttp2=GetXmlHttpObject()
-
-
//If we cant do the request error out
-
if (xmlHttp==null || xmlHttp2==null ) {
-
alert ("Browser does not support HTTP Request")
-
return
-
}
-
-
-
//First build the navigation panel
-
var url="getuser.php?bid_id=<?=$bid_id;?>"
-
url=url+"&p="+pageno
-
url=url+"&t=nav"
-
url=url+"&sid="+Math.random()
-
-
//Once the page finished loading put it into the div
-
xmlHttp2.onreadystatechange=navDone
-
-
//Get the php page
-
xmlHttp2.open("GET",url,true)
-
xmlHttp2.send(null)
-
-
//Build the url to call
-
//Pass variables through the url
-
var url="getuser.php?bid_id=<?=$bid_id;?>"
-
url=url+"&p="+pageno
-
url=url+"&t=con"
-
url=url+"&sid="+Math.random()
-
-
//Once the page finished loading put it into the div
-
xmlHttp.onreadystatechange=stateChanged
-
-
//Get the php page
-
xmlHttp.open("GET",url,true)
-
xmlHttp.send(null)
-
-
setTimeout('showPage(pageno)', 4000);
-
}
-
-
function navDone() {
-
//IF this is getting called when the page is done loading then fill the pagination div
-
if (xmlHttp2.readyState==4 ) {
-
//Update the Div tag with the outputted text
-
document.getElementById("pgNavigation").innerHTML=xmlHttp2.responseText
-
}
-
}
-
-
function stateChanged() {
-
//IF this is getting called when the page is done loading the states then output the div
-
if (xmlHttp.readyState==4 ) {
-
//Update the Div tag with the outputted text
-
document.getElementById("pgContent").innerHTML=xmlHttp.responseText
-
-
}
-
}
-
-
function GetXmlHttpObject() {
-
//Determine what browser we are on and make a httprequest connection for ajax
-
var xmlHttp=null;
-
-
try {
-
// Firefox, Opera 8.0+, Safari
-
xmlHttp=new XMLHttpRequest();
-
}
-
catch (e) {
-
//Internet Explorer
-
try {
-
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e) {
-
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
}
-
-
return xmlHttp;
-
}
-
-
-
-
//Onload start the user off on page one
-
window.onload = showPage(pageno);
how can i change the pageno with the links?
Progress- good! Since it's to be continuous at intervals, I would recommend setInterval over setTimeout. Note that they're used slightly differently. The setInterval only needs to be called once and it will happily continue on its merry way. The onload would be the best place for that. Note, though, that the way you're currently using onload is incorrect. It needs to be assigned to a function, not the result of a function (see the suggestion I posted earlier).
One other thing before we move onto the links. In showPage if you want to use the global variable set to 1, you need to remove pageno in between the brackets.
if i live the showpage empty ,then the links dont work!
what i change now is - var pageno = 1;
-
function showPage() {
-
//Function that gets called
-
//Currently we only call one other sub, but this could change
-
showStates(pageno)
-
-
}
-
-
window.onload = function() {
-
setTimeout(showPage(),4000);
-
}
listen every thing is working as i want it!
the only think i need is to fix the pageno = 1 to be dynamic
like if i press the second page the pageno will have +1
- window.onload = function() {
-
setTimeout(showPage(),4000);
-
}
That would call it after 4 seconds, rather than immediately. Is that what you want?
For the links, just set them as I posted earlier: - <a href="#" onclick="pageno = 2; return false;">2</a>
-
<a href="#" onclick="pageno = 3; return false;">3</a>
and so on.
the problem is that there is no links ,the link is creted dynamicly, look at the php file ,if i had href links that could be easier!!
In post #20 where you've posted the PHP code, look at line number 98. That's where you need to change the link to set pageno to $page.
thanx alot man!!
your last post got me to where i wanted!!!
you are king :)
You're welcome. Glad to hear that you got it working :) Post again to the forum if you have more questions.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: empiresolutions |
last post by:
Im using this script, http://www.captain.at/howto-ajax-form-post-get.php, to make an ajax request to php via a drop-down (DD) select. This works fine. Then using this script,...
|
by: preetksaini |
last post by:
hi
i am having a page in which i have 3 dropdowns,values of 2nd dropdown comes based on 1st and values of 3rd dropdown come based on 2nd.using AJAX+PHP to load dropdowns.
but whenever i refresh...
|
by: jonathan184 |
last post by:
how to let ajax refresh a page every few secs
Hi I got a php page that did that is being fed data that changes every few secs, i need some help in doing some code in letting the page aut refresh...
|
by: Kaante |
last post by:
Hi,
I basically have two frames on my page, the top one contains users stats and the bottom frame contains the website.
I want to have a message icon on the top frame which would flash once the...
|
by: helraizer1 |
last post by:
Hi folks,
I have an AJAX script to refresh a certain element in the page. The problem is that the element I need it to refresh is a dynamic image.. but the way I've done it inserts the raw image...
|
by: abaybas |
last post by:
I'm creating a page in which a certain "content" part of the page is refreshed using ajax.
I do this by using a div#content, and it's child div#container.
the code:
...
...
|
by: christian |
last post by:
Hello
I use a AJAX refresh script on a page to test a $var state
<div>
<?
include ("include/refr.inc.php");
//ajax script for reload
require ("bd_inc.php");
//test the line state buzy or...
|
by: ziycon |
last post by:
Basically if there is a special character it will display fine on the page when you first go to the page but when you submit something new and the AJAX reloads the data on screen all special...
|
by: techbytes |
last post by:
I Am working in Ajax for inserting values into the database.After the value is inserted,a message showing "Successfully Inserted" is displayed.
I want to know whether i can able to refresh the...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
| |