473,840 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

count down timer - JavaScript inside Ajax not working

155 New Member
Hi all!

i got a countdown timer for auctions that runing.

i got a DIV that refreshs every 4 seconds
that DIV is refreshed by ajax ,the file that is refreshed is timer.php for example!!

my problem is that the timer.php is not showing up.
if i run the timer.php alone it is showing the timer ,the problem i think it's because the timer sits inside the ajax DIV and that is what i think making me the problem!!

any help please?


thanx :)
Dec 16 '08 #1
22 8231
pronerd
392 Recognized Expert Contributor
There is really not any way to make any suggestions if you do not post the relevant code you are asking about.
Dec 17 '08 #2
canabatz
155 New Member
my problem is that the javascript return from ajax is inside php file

the javascript is executed in php so the problem is the ECHO javascript ,that closeing the response!!

here is the code:

Expand|Select|Wrap|Line Numbers
  1. echo "<div id='$bid_id'></div>
  2. <script type=\"text/javascript\">
  3. var launchdate2=new cdLocalTime(\"$bid_id\", \"server-php\", 0, \"$exmonth $expdate[2], $expdate[0] ";
  4. if($expiretime=='0')
  5.     {echo "00:00:00";}
  6. else { echo $expiretime;}
  7. echo "\")
  8. launchdate2.displaycountdown(\"\", formatresults2)
  9. </script>";
  10. }   
  11. else // Show some other content
  12.         {
  13.         echo "<font color='#FF0000' size='3''>you can still bid</font>";
  14.  
  15.  
  16.         }
  17. ?>
the last echo is working if there is no time left ,if there is time left then it showing nothing.

i need help taking this javascript out of the php.

please help me with that!

thanx
Dec 18 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
You need to either eval the JavaScript or put the JavaScript code separately into the head of the calling page.
Dec 18 '08 #4
canabatz
155 New Member
i need the javascript to be where it should be between the php script.

i dont understand all those slashes :(

any help with that?

thanx
Dec 18 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
Either have two separate requests: one for the HTML and the other for the JavaScript code; or parse the response to get the script to either eval or append to the head of the parent document. You don't necessarily need it where you currently have it because the ID should be enough for it to find where the timer should be displayed.
Dec 18 '08 #6
canabatz
155 New Member
my problem is the ajax that look for the response from the div,
now the javascript is executed by echo ,so the ajax is taking just the script as respond

please help me take the javascript from the echo, there im stuck :(

thanx
Dec 18 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
If we take the split route, move lines 3-8 into their own mini script and call that separately. Then you can just eval the response.
Dec 18 '08 #8
canabatz
155 New Member
here is the ajax code im using
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function getXMLHttp()
  3. {
  4.  
  5. var xmlHttp;
  6.  
  7.   try
  8.   {
  9.     //Firefox, Opera 8.0+, Safari
  10.     xmlHttp = new XMLHttpRequest();
  11.   }
  12.   catch(e)
  13.   {
  14.     //Internet Explorer
  15.     try
  16.     {
  17.       xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  18.     }
  19.     catch(e)
  20.     {
  21.       try
  22.       {
  23.         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  24.       }
  25.       catch(e)
  26.       {
  27.         alert("Your browser does not support AJAX!")
  28.         return false;
  29.       }
  30.     }
  31.   }
  32.   return xmlHttp;
  33. }
  34.  
  35.  var xmlHttp;
  36.  
  37. function MakeRequest2()
  38. {
  39.   var xmlHttp = getXMLHttp();
  40.  
  41.   xmlHttp.onreadystatechange = function()
  42.   {
  43.     if(xmlHttp.readyState == 4)
  44.     {
  45.       HandleResponse(xmlHttp.responseText);
  46.     }
  47.   }
  48. nocache = Math.random();
  49.   xmlHttp.open("GET", "check2.php?nocache="+nocache); 
  50.   xmlHttp.send(null);
  51.  setTimeout('MakeRequest2()', 4000);
  52. }
  53.  
  54. function MakeRequests()
  55. {
  56.   var xmlHttp = getXMLHttp();
  57.  
  58.   xmlHttp.onreadystatechange = function()
  59.   {
  60.     if(xmlHttp.readyState == 4) 
  61.  
  62.     {  
  63.       HandleResponsec(xmlHttp.responseText);
  64.     }
  65.   }
  66. nocache = Math.random();
  67.   xmlHttp.open("GET", "main.php?nocache="+nocache, true); 
  68.   xmlHttp.send(null);
  69. }
  70.  
  71. function HandleResponsec(res)
  72. {
  73.   document.getElementById('content').innerHTML = res;
  74. }
  75.  
  76.  
  77. function HandleResponse(response)
  78. {
  79.   if (document.getElementById('id').innerHTML == response)
  80.     {
  81.  
  82.  
  83.  
  84.     }
  85.  
  86. else if (document.getElementById('id').innerHTML = response)
  87.  
  88.     {
  89. MakeRequests();
  90.  
  91.     }
  92.  
  93.  
  94.  
  95. }
  96.  
  97.  
  98. window.onload=MakeRequest2();
  99.     </script>
the "content" div is empty if there is time left ,if there is no time left ,it writing me that there is no more time ,it's like the ajax is refusing to display the timer :)

what can be wrong with this?

thanx
Dec 18 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
For the JavaScript, you will need to eval, e.g.
Expand|Select|Wrap|Line Numbers
  1. eval(xmlHttp.responseText);
but this would be if the response is pure JavaScript. Alternatively, you can append to the head using something like:
Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. script.type="text/javascript";
  3. var txt = document.createTextNode(xmlHttp.responseText);
  4. script.appendChild(txt);
  5. document.getElementsByTagName("head")[0].appendChild(script);
This would be if you only had one line. If you return more than one line, you will need to split them up by newline and append the text nodes one by one.
Dec 19 '08 #10

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

Similar topics

2
3606
by: HeroinNO.4 | last post by:
Copy the code below and save in a .htm file, for example : 1.htm, then run it in browser, you'll see a cool count down timer ! If it doesn't work, you may open http://www.fillweb.com in IE and View->Source, and the latest version of count down timer will show you ! <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
1
1927
by: HeroinNO.4 | last post by:
Hello guys, sorry for my last version has a little "feature"(MS always call his bug "feature"), and now I fixed it and show the source to you all ! Just as the last version, copy the code below and save in a .htm file, fox example : "1.htm", and run it in a browser support JavaScript 1.1 or later, the cool count down timer will show you ! If it doesn't work, you may open http://www.fillweb.com in IE, and View->Source to see the latest...
2
2118
by: HeroinNO.4 | last post by:
Hello guys, now the source code updated to November 06, 2006 00:00 GMT,and now I fixed it and show the source to you all ! Just as the last version, copy the code below and save in a .htm file, fox example : "1.htm", and run it in a browser support JavaScript 1.1 or later, the cool count down timer will show you ! If it doesn't work, you may open http://www.fillweb.com in IE, and View->Source to see the latest version of source code !
1
2755
by: HeroinNO.4 | last post by:
You can open http://www.fillweb.com in IE and View->Source to see the latest version full featured count down timer source code, or you may also copy the code below and save in a "*.htm" file, for example "countdown.htm", and open it in browser, you'll see the full featured count down timer ! <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html;
2
2735
by: HeroinNO.4 | last post by:
Hello everyone! Now the latest version of free count down timer source code is available in http://www.fillweb.com/countdown.htm, you can open it in IE and View->Source to see the latest version source code, also you may copy the code below and save in a ".htm" file, and run it in browser, a cool count down timer will show you ! <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type"...
7
3311
by: HeroinNO.4 | last post by:
Hello guys, free count down timer source code has updated to 06/11/27, you can copy the code below and save in a ".htm" file and run it in a browser support javascript 1.1 or later, or you can open http:\\www.fillweb.com\countdown.htm, if you are using IE, you may View->Source to see the latest version of source code ! <html> <head> <meta http-equiv="Content-Language" content="en-us">
7
11614
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi everybody, I'm using a system.timers.timer object like this: Dim aTimer As New System.Timers.Timer() In my page_load event I use this: aTimer.Interval = 5000 aTimer.Enabled = True AddHandler aTimer.Elapsed, AddressOf OnTimedEvent .....
3
6169
missshaikh
by: missshaikh | last post by:
Hi all, i need the count down timer when button click the timer start and count down work on ASP.net :( i have one timer which is on JavaScript that run page onload . but i need the Button click my code is here... <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
4
5365
by: Peter | last post by:
ASP.NET I have an application which use ASP.NET Autocomplete extender which works great. But I have a question how to update all the fields on the screen using Ajax. Users starts typing in a text field which causes the Autocomplete extender to display 10 like items, after the users selects an item (which is a key in the database) I want the application to go to the database retrieve a record and populate the fields.
0
9860
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10603
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10301
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7838
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5685
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4076
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.