Hoping to implement an AJAX timer

JavaScript and client side scripting.

Moderator: General Moderators

impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Sorted now.

Since 10am I've been looking for a script to do this and it's taken me untill now 4pm to find the only script that does that

http://codewalkers.com/tutorials/99/2.html

Thank you for your help.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

That's bad code, but I guess if it works...

Incidentally, you probably just had the wrong path to jQuery.js
User avatar
Hornet83
Forum Newbie
Posts: 4
Joined: Mon Feb 12, 2007 2:03 am
Location: Melbourne, AUS

Post by Hornet83 »

Hi Kieran,

I've been looking to do something very similar, except that I want a certain section of a page (within a div) to be filled with contents from a php page when I click on a link.

Code: Select all

<?php
   $date=date('l dS \of F Y h:i:s A');
   echo "<h1>$date</h1>";
?>
Taking the jquery code from your previous reply in the same thread, I added it to the onclick event of a link. Basically, the date and time should be displayed every time you click on the link.

Code: Select all

<html>
<head>
   <title> your (my??) awesome page </title>
   <meta name="Generator" content="EditPlus" />
   <meta name="Author" content="Kieran Huggins - http://kieran.ca" />
   <script type="text/javascript" src="jquery.js"></script>
</head>
<body>
   <h1>HELLO</h1>
   <a href="#" onclick="$(function(){$('#ajaxDiv').load('sample.php');});">OPEN SESAME!</a>
   <div id="ajaxDiv"></div>
</body>
</html>
I got it to work fine on Firefox, but it only works the first time the page is displayed when I test it on IE. Subsequent clicking of the link does not update the time displayed. Here is a link to the page.

http://hornet83.no-ip.org/sample/test

Why does it work correctly on Firefox but not on IE (6.0)???

Thanks,
Ray
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Seems like IE is caching the result of the page for some reason - try changing the url to 'sample.php?'
User avatar
Hornet83
Forum Newbie
Posts: 4
Joined: Mon Feb 12, 2007 2:03 am
Location: Melbourne, AUS

Post by Hornet83 »

Changing the code to

Code: Select all

......xDiv').load('sample.php?');})...
still didn't work on IE, works fine on firefox.

That must be some caching done by IE, since even refreshing the page (which clears the content of the DIV), still displays the data from when the link was first clicked on. Only closing the browser window and reopening the page clears the cache.

*sigh*... IE...*sigh*
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

it just hit me - you should be using

Code: Select all

<html>
<head>
   <title> your (my??) awesome page </title>
   <meta name="Generator" content="EditPlus" />
   <meta name="Author" content="Kieran Huggins - http://kieran.ca" />
   <script type="text/javascript" src="jquery.js"></script>
</head>
<body>
   <h1>HELLO</h1>
   <a href="#" onclick="$('#ajaxDiv').load('sample.php');">OPEN SESAME!</a>
   <div id="ajaxDiv"></div>
</body>
</html>
since the "$(function(){...});"is autoloader code.

Check out http://www.visualjquery.com/1.1.1.html - it's a great reference!
User avatar
Hornet83
Forum Newbie
Posts: 4
Joined: Mon Feb 12, 2007 2:03 am
Location: Melbourne, AUS

Post by Hornet83 »

Taking out the autoload function still produced the same behaviour.....

Thanks for the VisualQuery link though. Looking under AJAX, I found another function called loadIfModified.

Great was my joy when I replaced

Code: Select all

<a href="#" onclick="$('#ajaxDiv').load('sample.php');">OPEN SESAME!</a>
to

Code: Select all

<a href="#" onclick="$('#ajaxDiv').loadIfModified('sample.php');">OPEN SESAME!</a>
It worked on IE!!!! Well, my joy was cut short when it didn't work on Firefox using loadIfModified. :(

Modified my test page, with two links, one using the simple load and the other using loadIfModified. http://hornet83.no-ip.org/sample/test

Any ideas?
Post Reply