jQuery

Create an ajax call with jQuery


	  $.ajax({
		  type: "POST",
		  url: "http://192.168.0.205:3030",
		  data: { 
			  username: "Dribbit", 
			  score: 1590 
			}
		})
		.done(function( msg ) {
		    console.log( "Message returned from the server: " + msg );
		});

Create a simple countdown object


/**
 * Create and process a new Countdown object.
 * 
 * @param seconds
 *  Integer
 */
function Countdown(seconds) {
	
	$('#timer').html(seconds);
	
	var timer = window.setInterval(function() {
	  if (seconds === 0) {
        clearInterval(timer);
        return;
	  }
      seconds -= 1;
      $('#timer').html(seconds);
	}, 1000);
	
	this.stop = function() {
      clearInterval(timer);
	}
	
}

Create a simple timer object


/**
 * A Timer object.
 */
function Timer() {
	
	var time = 0;
	$('#timer').html(time);
	
	var timer = window.setInterval(function() {
      time += 1;
      $('#timer').html(time);
	}, 1000);
	
	this.stop = function() {
      clearInterval(timer);
      $('#timer').html(time);
	}
	
}
Subscribe to RSS - jQuery