473,287 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

AJAX refresh!! where to put the timer?

155 100+
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!!


Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. //Global vars to hold connection to web pages
  3. var request;
  4.  
  5. function getHTTPObject() 
  6. {
  7.     var xhr = false;
  8.     if (window.XMLHttpRequest) 
  9.     {
  10.         xhr = new XMLHttpRequest();
  11.     } else if (window.ActiveXObject) {
  12.         try 
  13.         {
  14.             xhr = new ActiveXObject("Msxml2.XMLHTTP");
  15.         } 
  16.         catch(e) 
  17.         {
  18.             try 
  19.             {
  20.                 xhr = new ActiveXObject("Microsoft.XMLHTTP");
  21.             } 
  22.             catch(e) 
  23.             {
  24.                 xhr = false;
  25.             }
  26.         }
  27.     }
  28.     return xhr;
  29. }
  30.  
  31. var xmlHttp
  32. var xmlHttp2
  33.  
  34. function showPage(str) { 
  35.     //Function that gets called
  36.     //Currently we only call one other sub, but this could change
  37.     showStates(str)
  38. }
  39.  
  40.  
  41. function showStates(str) { 
  42.     //This sub will populate a table with all the states and get the 
  43.     //pagination built
  44.  
  45.     //Make the AJAX connection for both the navigation and content
  46.     xmlHttp=GetXmlHttpObject()
  47.     xmlHttp2=GetXmlHttpObject()
  48.  
  49.     //If we cant do the request error out
  50.     if (xmlHttp==null || xmlHttp2==null ) {
  51.          alert ("Browser does not support HTTP Request")
  52.          return
  53.     }
  54.  
  55.     //First build the navigation panel
  56.     var url="getuser.php?bid_id=<?=$bid_id;?>"
  57.     url=url+"&p="+str
  58.     url=url+"&t=nav"
  59.     url=url+"&sid="+Math.random()
  60.  
  61.     //Once the page finished loading put it into the div
  62.     xmlHttp2.onreadystatechange=navDone 
  63.  
  64.     //Get the php page
  65.     xmlHttp2.open("GET",url,true)
  66.     xmlHttp2.send(null)
  67.  
  68.     //Build the url to call
  69.     //Pass variables through the url
  70.     var url="getuser.php?bid_id=<?=$bid_id;?>"
  71.     url=url+"&p="+str
  72.     url=url+"&t=con"
  73.     url=url+"&sid="+Math.random()
  74.  
  75.     //Once the page finished loading put it into the div
  76.     xmlHttp.onreadystatechange=stateChanged 
  77.  
  78.     //Get the php page
  79.     xmlHttp.open("GET",url,true)
  80.     xmlHttp.send(null)
  81.  
  82.  
  83. }
  84.  
  85. function navDone() { 
  86.     //IF this is getting called when the page is done loading then fill the pagination div
  87.     if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") { 
  88.          //Update the Div tag with the outputted text
  89.          document.getElementById("pgNavigation").innerHTML=xmlHttp2.responseText 
  90.     } 
  91. }
  92.  
  93. function stateChanged() { 
  94.     //IF this is getting called when the page is done loading the states then output the div
  95.     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
  96.          //Update the Div tag with the outputted text
  97.          document.getElementById("pgContent").innerHTML=xmlHttp.responseText 
  98.     } 
  99. }
  100.  
  101. function GetXmlHttpObject() {
  102.     //Determine what browser we are on and make a httprequest connection for ajax
  103.     var xmlHttp=null;
  104.  
  105.     try {
  106.          // Firefox, Opera 8.0+, Safari
  107.          xmlHttp=new XMLHttpRequest();
  108.     }
  109.     catch (e) {
  110.          //Internet Explorer
  111.          try {
  112.               xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  113.           }
  114.          catch (e) {
  115.               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  116.           }
  117.     }
  118.  
  119.     return xmlHttp;
  120. }
  121.  
  122. function plusOne() {
  123.     //This is just a second counter to prove that we arent refreshing 
  124.     // If using the content ('childNode') of an id element...
  125.     var spanEl = document.getElementById('spanEl');
  126.     spanEl.childNodes[0].nodeValue = ( parseInt(spanEl.childNodes[0].nodeValue) + 1 );
  127. }
  128.  
  129. //Creates a timer 
  130.  
  131.  
  132. //Starts the counter
  133. window.onload = plusOne;
  134.  
  135. //Onload start the user off on page one
  136. window.onload = showPage("1");
  137.  
  138. </script>    
Oct 28 '08 #1
29 8108
canabatz
155 100+
i fixed it thanx1!!!! :)
Oct 29 '08 #2
acoder
16,027 Expert Mod 8TB
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.
Oct 29 '08 #3
canabatz
155 100+
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:

Expand|Select|Wrap|Line Numbers
  1. function showPage(str) { 
  2.   //Function that gets called
  3.   //Currently we only call one other sub, but this could change
  4.   showStates(str)
  5. setTimeout('showPage("1")', 4000);
  6.  }
  7.  
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!!
Oct 29 '08 #4
acoder
16,027 Expert Mod 8TB
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.
Oct 30 '08 #5
canabatz
155 100+
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!!
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. //Global vars to hold connection to web pages
  3.  
  4.  
  5. var request;
  6.  
  7. function getHTTPObject() 
  8. {
  9.     var xhr = false;
  10.     if (window.XMLHttpRequest) 
  11.     {
  12.         xhr = new XMLHttpRequest();
  13.     } else if (window.ActiveXObject) {
  14.         try 
  15.         {
  16.             xhr = new ActiveXObject("Msxml2.XMLHTTP");
  17.         } 
  18.         catch(e) 
  19.         {
  20.             try 
  21.             {
  22.                 xhr = new ActiveXObject("Microsoft.XMLHTTP");
  23.             } 
  24.             catch(e) 
  25.             {
  26.                 xhr = false;
  27.             }
  28.         }
  29.     }
  30.     return xhr;
  31. }
  32.  
  33. var xmlHttp
  34. var xmlHttp2
  35.  
  36. function showPage(str) { 
  37.     //Function that gets called
  38.     //Currently we only call one other sub, but this could change
  39.     showStates(str)
  40.  
  41.  
  42. }
  43.  
  44.  
  45. function showStates(str) { 
  46.     //This sub will populate a table with all the states and get the 
  47.     //pagination built
  48.  
  49.  
  50.     //Make the AJAX connection for both the navigation and content
  51.     xmlHttp=GetXmlHttpObject()
  52.     xmlHttp2=GetXmlHttpObject()
  53.  
  54.     //If we cant do the request error out
  55.     if (xmlHttp==null || xmlHttp2==null ) {
  56.          alert ("Browser does not support HTTP Request")
  57.          return
  58.     }
  59.  
  60.  
  61.     //First build the navigation panel
  62.     var url="getuser.php?bid_id=<?=$bid_id;?>"
  63.     url=url+"&p="+str
  64.     url=url+"&t=nav"
  65.     url=url+"&sid="+Math.random()
  66.  
  67.     //Once the page finished loading put it into the div
  68.     xmlHttp2.onreadystatechange=navDone 
  69.  
  70.     //Get the php page
  71.     xmlHttp2.open("GET",url,true)
  72.     xmlHttp2.send(null)
  73.  
  74.     //Build the url to call
  75.     //Pass variables through the url
  76.     var url="getuser.php?bid_id=<?=$bid_id;?>"
  77.     url=url+"&p="+str
  78.     url=url+"&t=con"
  79.     url=url+"&sid="+Math.random()
  80.  
  81.     //Once the page finished loading put it into the div
  82.     xmlHttp.onreadystatechange=stateChanged 
  83.  
  84.     //Get the php page
  85.     xmlHttp.open("GET",url,true)
  86.     xmlHttp.send(null)
  87.  
  88.  
  89. }
  90.  
  91. function navDone() { 
  92.     //IF this is getting called when the page is done loading then fill the pagination div
  93.     if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") { 
  94.          //Update the Div tag with the outputted text
  95.          document.getElementById("pgNavigation").innerHTML=xmlHttp2.responseText 
  96.     } 
  97. }
  98.  
  99. function stateChanged() { 
  100.     //IF this is getting called when the page is done loading the states then output the div
  101.     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
  102.          //Update the Div tag with the outputted text
  103.          document.getElementById("pgContent").innerHTML=xmlHttp.responseText 
  104.     } 
  105. }
  106.  
  107. function GetXmlHttpObject() {
  108.     //Determine what browser we are on and make a httprequest connection for ajax
  109.     var xmlHttp=null;
  110.  
  111.     try {
  112.          // Firefox, Opera 8.0+, Safari
  113.          xmlHttp=new XMLHttpRequest();
  114.     }
  115.     catch (e) {
  116.          //Internet Explorer
  117.          try {
  118.               xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  119.           }
  120.          catch (e) {
  121.               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  122.           }
  123.     }
  124.  
  125.     return xmlHttp;
  126. }
  127.  
  128.  
  129.  
  130. //Onload start the user off on page one
  131. window.onload = showPage("1");
  132.  
  133.  
  134. </script>
Expand|Select|Wrap|Line Numbers
  1. //############################################
  2. //First get the page value passed to this page
  3. $pageNum='';
  4. if (isset($_GET["p"])) {
  5.     $pageNum=$_GET["p"];
  6. }
  7.  
  8. $type='';
  9. if (isset($_GET["t"])) {
  10.     $type=$_GET["t"];
  11. }
  12.  
  13. //############################################
  14. //Now import the settings
  15. header('Content-Type: text/html; charset=windows-1255');
  16. include("conn.php");
  17. $RPP=50;
  18.  
  19. $PrevIc=        "images/bprv.gif";
  20. $FirstIc=        "images/bfrst.gif";
  21. $NextIc=        "images/bnxt.gif";
  22. $LastIc=        "images/blst.gif";
  23.  
  24. $dPrevIc=        "images/dprv.gif";
  25. $dFirstIc=        "images/dfrst.gif";
  26. $dNextIc=        "images/dnxt.gif";
  27. $dLastIc=        "images/dlst.gif";
  28. //############################################
  29. //Connect to the db
  30.  
  31. //############################################
  32. //Get a quick count of all the rows
  33. $querys   = "SELECT * FROM bidding_details where bid_id=$bid_id";
  34. $results  = mysql_query($querys);
  35. $num=mysql_num_rows($results);
  36.  
  37. //############################################
  38. //If there are some rows then start the pagination
  39. if ($num>0) {
  40.     //Determine the maxpage and the offset for the query
  41.     $maxPage = ceil($bid_id/$RPP);
  42.     $offset = ($pageNum - 1) * $RPP;
  43.  
  44.     //Initiate the navigation bar
  45.     $nav  = '';
  46.  
  47.     //get low end
  48.     $page = $pageNum-3;
  49.  
  50.     //get upperbound
  51.     $upper =$pageNum+3;
  52.  
  53.     if ($page <=0) {
  54.         $page=1;
  55.     }
  56.  
  57.     if ($upper >$maxPage) {
  58.         $upper =$maxPage;
  59.     }
  60.  
  61.     //Make sure there are 7 numbers (3 before, 3 after and current
  62.     if ($upper-$page <6){
  63.  
  64.         //We know that one of the page has maxed out
  65.         //check which one it is
  66.         //echo "$upper >=$maxPage<br>";
  67.         if ($upper >=$maxPage){
  68.             //the upper end has maxed, put more on the front end
  69.             //echo "to begining<br>";
  70.             $dif =$maxPage-$page;
  71.             //echo "$dif<br>";
  72.                 if ($dif==3){
  73.                     $page=$page-3;
  74.                 }elseif ($dif==4){
  75.                     $page=$page-2;
  76.                 }elseif ($dif==5){
  77.                     $page=$page-1;
  78.                 }
  79.         }elseif ($page <=1) {
  80.             //its the low end, add to upper end
  81.             //echo "to upper<br>";
  82.             $dif =$upper-1;
  83.  
  84.             if ($dif==3){
  85.                 $upper=$upper+3;
  86.             }elseif ($dif==4){
  87.                 $upper=$upper+2;
  88.             }elseif ($dif==5){
  89.                 $upper=$upper+1;
  90.             }
  91.         }
  92.     }
  93.  
  94.     if ($page <=0) {
  95.         $page=1;
  96.     }
  97.  
  98.     if ($upper >$maxPage) {
  99.         $upper =$maxPage;
  100.     }
  101.  
  102.     //These are the numbered links
  103.     for($page; $page <=  $upper; $page++) {
  104.         if ($page == $pageNum){
  105.             //If this is the current page then disable the link
  106.             $nav .= "$page";
  107.  
  108.         }else{
  109.             //If this is a different page then link to it
  110.             $nav .= " <a onclick='showPage(\"".$page."\")'>$page</a> ";
  111.         }
  112.     }
  113.  
  114.  
  115.  
  116.     if ($maxPage>1 AND $type=='nav') {
  117.         // print the navigation link
  118.         echo $first . $prev . $nav . $next . $last;
  119.     }elseif ($maxPage>1 AND $type=='con') {
  120.         //Build the header
  121.         echo "<table width='517' border='0' cellspacing='0' cellpadding='0'>";
  122.         echo "    <tr>";
  123.         echo "<td align='center' width='90' bgcolor='#FF9900'>לקוח</td>";
  124. echo "<td align='center' width='90' bgcolor='#FF9900'>שם</td>";
  125. echo "<td align='center' width='90' bgcolor='#FF9900'>עיר</td>";
  126. echo "<td align='center' width='90' bgcolor='#FF9900'>הצעה</td>";
  127. echo "<td align='center' width='90' bgcolor='#FF9900'>מיקום</td>";
  128.         echo "    </tr>";
  129.  
  130.         //Get all the rows
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
Oct 30 '08 #6
acoder
16,027 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.     setInterval(showPage,4000);
  3. }
You could have the page number as a global variable which can be incremented in showPage.
Oct 30 '08 #7
canabatz
155 100+
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!
Oct 30 '08 #8
acoder
16,027 Expert Mod 8TB
OK, on the first page when you're on page 2, what's the full page URL including after the ?
Oct 30 '08 #9
canabatz
155 100+
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
Oct 30 '08 #10
acoder
16,027 Expert Mod 8TB
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?
Oct 30 '08 #11
canabatz
155 100+
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.
Oct 30 '08 #12
acoder
16,027 Expert Mod 8TB
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.
Oct 30 '08 #13
canabatz
155 100+
if i knew how to do it ,it was good then !
im not this good in JS or PHP :)

:(

thanx alot!!
Oct 30 '08 #14
acoder
16,027 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. var pageno = 1;
4. Replace str in showPage() with pageno.

5. Change the links to set pageno instead of calling showPage:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="pageno = 2; return false;">2</a>
Oct 30 '08 #15
canabatz
155 100+
thanx alot man!! , when i get home im going to try it!!!!


thanks!!!
Oct 30 '08 #16
canabatz
155 100+
i try everything and i cannot figure it out how to do it :(

any help will be appreciated !!
thanx
Oct 30 '08 #17
acoder
16,027 Expert Mod 8TB
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?
Oct 31 '08 #18
canabatz
155 100+
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!!
Oct 31 '08 #19
canabatz
155 100+
here are both of the files!

the java script
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. var request;
  4.  
  5. function getHTTPObject() 
  6. {
  7.     var xhr = false;
  8.     if (window.XMLHttpRequest) 
  9.     {
  10.         xhr = new XMLHttpRequest();
  11.     } else if (window.ActiveXObject) {
  12.         try 
  13.         {
  14.             xhr = new ActiveXObject("Msxml2.XMLHTTP");
  15.         } 
  16.         catch(e) 
  17.         {
  18.             try 
  19.             {
  20.                 xhr = new ActiveXObject("Microsoft.XMLHTTP");
  21.             } 
  22.             catch(e) 
  23.             {
  24.                 xhr = false;
  25.             }
  26.         }
  27.     }
  28.     return xhr;
  29. }
  30.  
  31. var xmlHttp
  32. var xmlHttp2
  33.  
  34. function showPage(str) { 
  35.  
  36.     showStates(str)        
  37. }
  38.  
  39. function showStates(str) { 
  40.  
  41.     xmlHttp=GetXmlHttpObject()
  42.     xmlHttp2=GetXmlHttpObject()
  43.  
  44.     if (xmlHttp==null || xmlHttp2==null ) {
  45.          alert ("Browser does not support HTTP Request")
  46.          return
  47.     }
  48.     var url="getuser.php?bid_id=<?=$bid_id;?>"
  49.     url=url+"&p="+str
  50.     url=url+"&t=nav"
  51.     url=url+"&sid="+Math.random()
  52.  
  53.     xmlHttp2.onreadystatechange=navDone 
  54.  
  55.     xmlHttp2.open("GET",url,true)
  56.     xmlHttp2.send(null)
  57.  
  58.     var url="getuser.php?bid_id=<?=$bid_id;?>"
  59.     url=url+"&p="+str
  60.     url=url+"&t=con"
  61.     url=url+"&sid="+Math.random()
  62.  
  63.     xmlHttp.onreadystatechange=stateChanged 
  64.  
  65.     xmlHttp.open("GET",url,true)
  66.     xmlHttp.send(null)
  67. }
  68.  
  69. function navDone() { 
  70.  
  71.     if (xmlHttp2.readyState==4 ) { 
  72.  
  73.          document.getElementById("pgNavigation").innerHTML=xmlHttp2.responseText 
  74.     } 
  75. }
  76. function stateChanged() { 
  77.  
  78.     if (xmlHttp.readyState==4 ) {      
  79.          document.getElementById("pgContent").innerHTML=xmlHttp.responseText         
  80.     } 
  81. }
  82. function GetXmlHttpObject() {
  83.  
  84.     var xmlHttp=null;
  85.     try {
  86.          xmlHttp=new XMLHttpRequest();
  87.     }
  88.     catch (e) {
  89.          try {
  90.               xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  91.           }
  92.          catch (e) {
  93.               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  94.           }
  95.     }    
  96.     return xmlHttp;
  97. }
  98.  
  99. window.onload = showPage("1");
  100.  
  101. </script>
Expand|Select|Wrap|Line Numbers
  1. //////  the php file//////////
  2. <?
  3.  
  4. $pageNum='';
  5. if (isset($_GET["p"])) {
  6.     $pageNum=$_GET["p"];
  7. }
  8.  
  9. $type='';
  10. if (isset($_GET["t"])) {
  11.     $type=$_GET["t"];
  12. }
  13.  
  14. $RPP=50;
  15.  
  16. //############################################
  17. //Get a quick count of all the rows
  18. $querys   = "SELECT * FROM bidding_details where bid_id=$bid_id";
  19. $results  = mysql_query($querys);
  20. $num=mysql_num_rows($results);
  21.  
  22. //############################################
  23. //If there are some rows then start the pagination
  24. if ($num>0) {
  25.     //Determine the maxpage and the offset for the query
  26.     $maxPage = ceil($bid_id/$RPP);
  27.     $offset = ($pageNum - 1) * $RPP;
  28.  
  29.     //Initiate the navigation bar
  30.     $nav  = '';
  31.  
  32.     //get low end
  33.     $page = $pageNum-3;
  34.  
  35.     //get upperbound
  36.     $upper =$pageNum+3;
  37.  
  38.     if ($page <=0) {
  39.         $page=1;
  40.     }
  41.  
  42.     if ($upper >$maxPage) {
  43.         $upper =$maxPage;
  44.     }
  45.  
  46.     //Make sure there are 7 numbers (3 before, 3 after and current
  47.     if ($upper-$page <6){
  48.  
  49.         //We know that one of the page has maxed out
  50.         //check which one it is
  51.         //echo "$upper >=$maxPage<br>";
  52.         if ($upper >=$maxPage){
  53.             //the upper end has maxed, put more on the front end
  54.             //echo "to begining<br>";
  55.             $dif =$maxPage-$page;
  56.             //echo "$dif<br>";
  57.                 if ($dif==3){
  58.  
  59.                     $page=$page-3;
  60.                 }elseif ($dif==4){
  61.                     $page=$page-2;
  62.                 }elseif ($dif==5){
  63.                     $page=$page-1;
  64.                 }
  65.         }elseif ($page <=1) {
  66.             //its the low end, add to upper end
  67.             //echo "to upper<br>";
  68.             $dif =$upper-1;
  69.  
  70.             if ($dif==3){
  71.  
  72.                 $upper=$upper+3;
  73.             }elseif ($dif==4){
  74.                 $upper=$upper+2;
  75.             }elseif ($dif==5){
  76.                 $upper=$upper+1;
  77.             }
  78.         }
  79.     }
  80.  
  81.     if ($page <=0) {
  82.         $page=1;
  83.     }
  84.  
  85.     if ($upper >$maxPage) {
  86.         $upper =$maxPage;
  87.     }
  88.  
  89.     //These are the numbered links
  90.     for($page; $page <=  $upper; $page++) {
  91.         if ($page == $pageNum){
  92.             //If this is the current page then disable the link
  93.             $nav .= "$page" ;
  94.  
  95.  
  96.         }else{
  97.             //If this is a different page then link to it
  98.              $nav .= " <a onclick='showPage(\"".$page."\")'>$page</a> ";
  99.  
  100.         }
  101.     }
  102.  
  103.  
  104.  
  105.     if ($maxPage>1 AND $type=='nav') {
  106.  
  107.         // print the navigation link
  108.         echo $first . $prev . $nav . $next . $last;
  109.     }elseif ($maxPage>1 AND $type=='con') {
  110.  
  111.         //Build the header
  112.  
  113.         ?>
Oct 31 '08 #20
acoder
16,027 Expert Mod 8TB
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.
Oct 31 '08 #21
canabatz
155 100+
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:
Expand|Select|Wrap|Line Numbers
  1. var pageno = 1;
  2. function showPage(pageno) { 
  3.     //Function that gets called
  4.     //Currently we only call one other sub, but this could change
  5.     showStates(pageno)
  6.  
  7. }
  8.  
  9.  
  10. function showStates(pageno) { 
  11.     //This sub will populate a table with all the states and get the 
  12.     //pagination built
  13.  
  14.  
  15.     //Make the AJAX connection for both the navigation and content
  16.     xmlHttp=GetXmlHttpObject()
  17.     xmlHttp2=GetXmlHttpObject()
  18.  
  19.     //If we cant do the request error out
  20.     if (xmlHttp==null || xmlHttp2==null ) {
  21.          alert ("Browser does not support HTTP Request")
  22.          return
  23.     }
  24.  
  25.  
  26.     //First build the navigation panel
  27.     var url="getuser.php?bid_id=<?=$bid_id;?>"
  28.     url=url+"&p="+pageno
  29.     url=url+"&t=nav"
  30.     url=url+"&sid="+Math.random()
  31.  
  32.     //Once the page finished loading put it into the div
  33.     xmlHttp2.onreadystatechange=navDone 
  34.  
  35.     //Get the php page
  36.     xmlHttp2.open("GET",url,true)
  37.     xmlHttp2.send(null)
  38.  
  39.     //Build the url to call
  40.     //Pass variables through the url
  41.     var url="getuser.php?bid_id=<?=$bid_id;?>"
  42.     url=url+"&p="+pageno
  43.     url=url+"&t=con"
  44.     url=url+"&sid="+Math.random()
  45.  
  46.     //Once the page finished loading put it into the div
  47.     xmlHttp.onreadystatechange=stateChanged 
  48.  
  49.     //Get the php page
  50.     xmlHttp.open("GET",url,true)
  51.     xmlHttp.send(null)
  52.  
  53.     setTimeout('showPage(pageno)', 4000);
  54. }
  55.  
  56. function navDone() { 
  57.     //IF this is getting called when the page is done loading then fill the pagination div
  58.     if (xmlHttp2.readyState==4 ) { 
  59.          //Update the Div tag with the outputted text
  60.          document.getElementById("pgNavigation").innerHTML=xmlHttp2.responseText 
  61.     } 
  62. }
  63.  
  64. function stateChanged() { 
  65.     //IF this is getting called when the page is done loading the states then output the div
  66.     if (xmlHttp.readyState==4 ) { 
  67.          //Update the Div tag with the outputted text
  68.          document.getElementById("pgContent").innerHTML=xmlHttp.responseText 
  69.  
  70.     } 
  71. }
  72.  
  73. function GetXmlHttpObject() {
  74.     //Determine what browser we are on and make a httprequest connection for ajax
  75.     var xmlHttp=null;
  76.  
  77.     try {
  78.          // Firefox, Opera 8.0+, Safari
  79.          xmlHttp=new XMLHttpRequest();
  80.     }
  81.     catch (e) {
  82.          //Internet Explorer
  83.          try {
  84.               xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  85.           }
  86.          catch (e) {
  87.               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  88.           }
  89.     }
  90.  
  91.     return xmlHttp;
  92. }
  93.  
  94.  
  95.  
  96. //Onload start the user off on page one
  97. window.onload = showPage(pageno);
how can i change the pageno with the links?
Oct 31 '08 #22
acoder
16,027 Expert Mod 8TB
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.
Oct 31 '08 #23
canabatz
155 100+
if i live the showpage empty ,then the links dont work!

what i change now is

Expand|Select|Wrap|Line Numbers
  1. var pageno = 1;
  2. function showPage() { 
  3.     //Function that gets called
  4.     //Currently we only call one other sub, but this could change
  5.     showStates(pageno)
  6.  
  7. }
  8.  
  9. window.onload = function() {
  10.     setTimeout(showPage(),4000);
  11. }
Oct 31 '08 #24
canabatz
155 100+
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
Oct 31 '08 #25
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.     setTimeout(showPage(),4000);
  3. }
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:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="pageno = 2; return false;">2</a>
  2. <a href="#" onclick="pageno = 3; return false;">3</a>
and so on.
Oct 31 '08 #26
canabatz
155 100+
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!!
Oct 31 '08 #27
acoder
16,027 Expert Mod 8TB
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.
Oct 31 '08 #28
canabatz
155 100+
thanx alot man!!

your last post got me to where i wanted!!!

you are king :)
Oct 31 '08 #29
acoder
16,027 Expert Mod 8TB
You're welcome. Glad to hear that you got it working :) Post again to the forum if you have more questions.
Oct 31 '08 #30

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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,...
9
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...
1
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...
5
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...
1
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...
1
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: ... ...
1
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...
1
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...
5
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...
0
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"....
0
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...
0
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...
0
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 =...
0
isladogs
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...
0
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...
1
isladogs
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...
0
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.