www.pokeroconnor.com

Ajax for Beginners

April4

Quickest and easiest tutorial, and should be your first starting point as it serves as a good, simple introduction to the XMLHttpRequest object. Then one of the first AJAX tutorials is here. Typical creation of the object:

function ajaxFunction()
{
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;
      }
    }
  }
  }

Unix time converter

April3

Thanks to the Captain for the handiest Unix time -to- date converter, and vice versa! 

And in case you ever need to create a Unix time format, you can use php’s date and mktime functions to do so:

$hour= date(”H”);

$minute= date(”i”);

$second= date(”s”);

$day = date(”j”);

$month = date(”n”);

$year = date(”Y”);

$unix_time = mktime($hour,$minute,$second, $month, $day, $year);

You can override your server’s timezone setting using date_default_timezone_set.

Javascript Auto Refresh Page

April3

Thanks to this excellent blog, this is how to get a page to auto refresh on a timer using javascript (in this example its on a 10 second timer):

<script type=”text/javascript” language=”javascript”> 

var reloadTimer = null;

window.onload = function()

{

    setReloadTime(10); // In this example we’ll use 10 seconds.

}

function setReloadTime(secs) 

{

    if (arguments.length == 1) {

        if (reloadTimer) clearTimeout(reloadTimer);

        reloadTimer = setTimeout(”setReloadTime()”, Math.ceil(parseFloat(secs) * 1000));

    }

    else {

        location.reload();

    }

}

</script>

And you can do the following to add a link to refresh the page:

<a href=”javascript:location.reload();”>Refresh the page</a>

reload() refreshes from the cache, so if you want to force it to get a fresh copy via GET from the server, pass ‘true’ as a param. E.g. <a onclick=”location.reload(true)” href=”#”>Refresh the page</a>

You can also do :<meta http-equiv=Refresh” content=n;url”/>, just leave off the url if you want to refresh to the current page.

Newer Entries »