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 :)
22 8139
There is really not any way to make any suggestions if you do not post the relevant code you are asking about.
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: - echo "<div id='$bid_id'></div>
-
<script type=\"text/javascript\">
-
var launchdate2=new cdLocalTime(\"$bid_id\", \"server-php\", 0, \"$exmonth $expdate[2], $expdate[0] ";
-
if($expiretime=='0')
-
{echo "00:00:00";}
-
else { echo $expiretime;}
-
echo "\")
-
launchdate2.displaycountdown(\"\", formatresults2)
-
</script>";
-
}
-
else // Show some other content
-
{
-
echo "<font color='#FF0000' size='3''>you can still bid</font>";
-
-
-
}
-
?>
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
You need to either eval the JavaScript or put the JavaScript code separately into the head of the calling page.
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
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.
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
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.
here is the ajax code im using - <script type="text/javascript">
-
function getXMLHttp()
-
{
-
-
var xmlHttp;
-
-
try
-
{
-
//Firefox, Opera 8.0+, Safari
-
xmlHttp = new XMLHttpRequest();
-
}
-
catch(e)
-
{
-
//Internet Explorer
-
try
-
{
-
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch(e)
-
{
-
try
-
{
-
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
catch(e)
-
{
-
alert("Your browser does not support AJAX!")
-
return false;
-
}
-
}
-
}
-
return xmlHttp;
-
}
-
-
var xmlHttp;
-
-
function MakeRequest2()
-
{
-
var xmlHttp = getXMLHttp();
-
-
xmlHttp.onreadystatechange = function()
-
{
-
if(xmlHttp.readyState == 4)
-
{
-
HandleResponse(xmlHttp.responseText);
-
}
-
}
-
nocache = Math.random();
-
xmlHttp.open("GET", "check2.php?nocache="+nocache);
-
xmlHttp.send(null);
-
setTimeout('MakeRequest2()', 4000);
-
}
-
-
function MakeRequests()
-
{
-
var xmlHttp = getXMLHttp();
-
-
xmlHttp.onreadystatechange = function()
-
{
-
if(xmlHttp.readyState == 4)
-
-
{
-
HandleResponsec(xmlHttp.responseText);
-
}
-
}
-
nocache = Math.random();
-
xmlHttp.open("GET", "main.php?nocache="+nocache, true);
-
xmlHttp.send(null);
-
}
-
-
function HandleResponsec(res)
-
{
-
document.getElementById('content').innerHTML = res;
-
}
-
-
-
function HandleResponse(response)
-
{
-
if (document.getElementById('id').innerHTML == response)
-
{
-
-
-
-
}
-
-
else if (document.getElementById('id').innerHTML = response)
-
-
{
-
MakeRequests();
-
-
}
-
-
-
-
}
-
-
-
window.onload=MakeRequest2();
-
</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
For the JavaScript, you will need to eval, e.g. - eval(xmlHttp.responseText);
but this would be if the response is pure JavaScript. Alternatively, you can append to the head using something like: - var script = document.createElement("script");
-
script.type="text/javascript";
-
var txt = document.createTextNode(xmlHttp.responseText);
-
script.appendChild(txt);
-
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.
like i said the main.php works fine if i run it alone ,i did succeed to take the javascript out of the php ,but it didnt change any thing !!
the problem is in the ajax script.
it's not displaying the timer ,it's just displaying if there is no time left!
thanx
What does check2.php do? You've missed the third parameter in open() and in the callback function HandleResponse(), the else is setting the innerHTML to the response.
this is a short check to the database to see if there is change in some thing.
if there is changes it will call the next call ,the main.php to refresh the results.
the main.php is sitting inside a DIV in my index.php
can you point me where there is something wrong in my ajax script?
thanx ;)
So, which one contains the JavaScript code? main.php? Have you got a test page that I can have a look at?
in index.php head ,there is the src of javascript.js
in javascript.js there is the call to two php files
check2.php checks for changes in the data base ,if there is changes it refeshes
the main.php that sit in the content DIV בונקר מכרזים ,its the file im runing inside the ajax DIV that dont show me the count down timer. if i run this file alone it showing me the timer ,if it's inside the div it's not showing me!! בונקר מכרזים it's my testing page that not showing me the timer.
thanx
in the header.php there is the source javascript for the timer. and in my test page there is the header twice just to be sure it is calling the source javascript for the timer
the ajax code: - function MakeRequests()
-
{
-
-
-
var xmlHttp1 = getXMLHttp();
-
-
xmlHttp1.onreadystatechange = function()
-
{
-
if(xmlHttp1.readyState == 4)
-
-
{
-
HandleResponsec(xmlHttp1.responseText);
-
}
-
}
-
-
nocache = Math.random();
-
xmlHttp1.open("GET", "main.php?nocache="+nocache, null);
-
xmlHttp1.send(null);
-
-
}
-
-
function HandleResponsec(res)
-
{
-
-
document.getElementById('content').innerHTML = res
-
}
in the main.php there is javascript that is not working ,what i need to do so the javascript will run?
thanx
Is the innerHTML of the content element definitely being updated?
Have you tried to confirm that the code is running as expected by either debugging with a tool such as FireBug for Firefox or by inserting alerts at various points and making sure that they are hit?
If the document is XHMTL then certain browsers will not allow the innerHTML of an element already within the DOM to be changed incase it is not valid XHTML. If this is the problem it can be resolved by creating an element and setting that elements innerHTML before adding it to the document. To do this change the HandleResponsec function to: -
function HandleResponsec(res)
-
{
-
-- declare variables.
-
var newElem, content;
-
-
-- create element and set innerHTML.
-
newElem = document.createElement('div');
-
newElem.innerHTML = res;
-
-
-- select the content element.
-
content = document.getElementById('content');
-
-
-- Ensure that the content element has been found.
-
if(content !== null){
-
content.appendChild(newElem);
-
}
-
}
This example wraps the content in a div. If the result is plain text then you could create a text node and add this to the content element directly. This will encode an HTML entities so this must only for text: -
function HandleResponsec(res)
-
{
-
-- declare variables.
-
var newText, content;
-
-
-- create text node.
-
newText = document.createTextNode(res);
-
-
-- select the content element.
-
content = document.getElementById('content');
-
-
-- Ensure that the content element has been found.
-
if(content !== null){
-
content.appendChild(newText);
-
}
-
}
I have assumed that there is a call to the MakeRequests function and that the getXMLHttp function returns an xmlHttpRequest object.
if i run the main.php alone it is working well with the javascript in it.
the javascript is runing in php code ,here it's the javascript code: - echo "<div id='$bid_id'></div>
-
<script type=\"text/javascript\">
-
var launchdate2=new cdLocalTime(\"$bid_id\", \"server-php\", 0, \"$exmonth $expdate[2], $expdate[0] ";
-
if($expiretime=='0')
-
{echo "00:00:00";}
-
else { echo $expiretime;}
-
echo "\")
-
launchdate2.displaycountdown(\"\", formatresults2)
-
</script>";
if im runing the all page ,then it's not working the javascript.
my code goes like that
index.php got javascript in the head ,the javascript is ajax script ,the return content is siting in a div 'content' ,in the content div the ajax is calling the main.php ,in the main.php there is the javascript that is not geting executed.
thanx alot!
im working on it for 5 days now and no success .
gits 5,390
Expert Mod 4TB
in case the javascript is delivered during an ajax-request the script will not be executed unless you eval() the script explicitly. javascript code is typically evaled during page-load and with an ajax-call that is just avaoided. so you need to eval the script in the response callback explicitly do get it executed.
kind regards
Threads merged. Please do not double post.
Moderator.
PS. You've posted the link which should make it easier to debug. Not had the time to look at it yet.
in this topic i understand that my problem is not what i look for!
i discover that my problem is the javascript inside the ajax content div ,so my problem is the other topic ,when some one is going to have problem like this ,he will find it there and not here ,this topic is countdown timer!!
m i right?
;)
Well, the problem was established from about the third post, so it has been the JavaScript problem all along.
I notice from the link that you posted that MakeRequests is undefined. It seems you've changed the code from what you had earlier.
main.php is a whole lot of code which is totally unnecessary for this purpose. Move the JavaScript code that you need into its own file and add that to the parent page.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |