Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dynamically load clock using ajax in qtip
8th February, 22:48
Post: #1
dynamically load clock using ajax in qtip
Hi Craig,

First off, thanks for the great plug-in!

I'm having trouble trying to display a clock in a qtip. Basically, I have a php page on my server that simply outputs the current time as a string. I found a previous thread where another user was trying to dynamically load content using AJAX each time a qtip was shown. I've implemented the code you wrote in response to that thread as such:
JS Code
api: {
      beforeShow: function update(){
         var url = this.options.content.url;
         var method = this.options.content.method;
         this.loadContent(url, method);
 
      }
     }


where url is a string that I defined earlier in the script. This works fine, and the content updates each time the qtip is shown, but what I'd really like to do is have the content in the qtip refresh every second while the qtip is being shown. In other words, so long as the qtip is visible, the content refreshes every second without the user having to move the mouse off the qtip and hover over it again. I thought I could try using the setTimeout function, but I haven't gotten very far with that. Do you have any suggestions?

Thanks in advance,

Ryan
Find all posts by this user
Quote this message in a reply
8th February, 23:37
Post: #2
RE: dynamically load clock using ajax in qtip
That seems like an awfully wasteful process. Why don't you just generate the initial time on the server and use JS's native Date object to countdown?

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
8th February, 23:58
Post: #3
RE: dynamically load clock using ajax in qtip
(8th February 23:37)Craig Wrote:  That seems like an awfully wasteful process. Why don't you just generate the initial time on the server and use JS's native Date object to countdown?

Agreed about the JS Date object...but it's actually not a clock that I'm trying to display (was saying that for simplicity, but the real application is a little different). The PHP file is actually being used to query a mySQL database that contains a field with the start time of a particular process. The PHP script calculates the difference between the current time and the process start time and outputs how long that process has been active along with some other stats.
Find all posts by this user
Quote this message in a reply
9th February, 16:54
Post: #4
RE: dynamically load clock using ajax in qtip
Well if you return some UNIX timestamps in a JSON wrapper you can use the Date object to parse it.

JS Code
ajax: {
	url: 'date.php',
	dataType: 'json',
	success: function(dates) {
		var d1 = new Date(dates.until),
			d2 = new Date(dates.other);
 
		// do something
	}
}

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Qtip data not find when using ajax pagereload reinier1991 1 74 10th May 07:52
Last Post: reinier1991
  [Solved] qTip Ajax data for text in a div akhil_csit 1 306 14th March 19:27
Last Post: Craig
  [Solved] creating a qtip with ajax contents based on computed uri params punk.kish 1 398 25th January 15:50
Last Post: Craig
  [Solved] Is there an easier way to show/hide tooltips dynamically? gloosemo 1 665 17th October 15:58
Last Post: Craig
  Ajax call not being made from qtip sz3y1w 1 882 7th September 19:55
Last Post: Craig
  [Solved] How to make qTip work with AJAX and a "enable/disable" checkbox? xzuttz 4 1,041 24th August 19:04
Last Post: Craig
  [Solved] Qtip and Lazy Load Plugin [Solved] usman 3 1,017 9th August 17:31
Last Post: Craig
  [Solved] Can't dynamically update content text! hoodedperson70 9 1,279 20th July 18:47
Last Post: hoodedperson70
  [Solved] Loading qtip on page load daysleeper 2 925 15th June 01:46
Last Post: daysleeper
  How to dynamically bind qtip hhke 1 853 13th June 14:36
Last Post: Craig



User(s) browsing this thread: 1 Guest(s)