$.ajax() callbacks not being executed

$.ajax() callbacks not being executed

I am trying to execute slightly more than "Hello, world" using .ajax() specifically and with both a success and error callback. I have:

  1. var MeasureClockSkew = function()
  2.     {
  3.     var that = this;
  4.     var lastButtonPress = new Date().getTime();
  5.     var registerError = function(XMLHttpRequest, textStatus, errorThrown)
  6.         {
  7.         alert("registerError called.");
  8.         $("#results").append($("li").addClass("error").append("Error: " + textStatus));
  9.         $("#button").attr("disabled", "false");
  10.         };
  11.     var registerSuccess = function(data, textStatus, XMLHttpRequest)
  12.         {
  13.         alert("registerSuccess called.");
  14.         try
  15.             {
  16.             var remote = JSON.parse(data).time();
  17.             var halfway = (lastButtonPress + new Date().getTime()) / 2;
  18.             var skew = (remote - halfway) / 1000;
  19.             $("#results").append($("li").addClass("success").append("Estimated clock skew: " + skew));
  20.             }
  21.         catch(error)
  22.             {
  23.             $("#results").append($("li").addClass("error").append("Error parsing JSON."));
  24.             }
  25.         $("#button").attr("disabled", "false");
  26.         };
  27.     var buttonPress = function()
  28.         {
  29.         alert("Begun buttonPress.");
  30.         lastButtonPress = new Date().getTime();
  31.         $("#button").attr("disabled", "true");
  32.         $.ajax(data = "", dataType = "json", error = this.registerError, success = this.registerSuccess, type = "POST", url = "/time/json");
  33.         alert("Finished buttonPress.");
  34.         };
  35.     return {
  36.         buttonPress: buttonPress
  37.         }
  38.     } ( );
  39. $("#button").click(MeasureClockSkew.buttonPress);

When I click on #button, it gives the "Begun buttonPress." and "Finished buttonPress." alerts, but not yet the alerts from the callbacks. Whether I specify

  1.         $.ajax(data = "", dataType = "json", error = this.registerError, success = this.registerSuccess, type = "POST", url = "/time/json")

or:

  1.         $.ajax(data = "", dataType = "json", error = registerError, success = registerSuccess, type = "POST", url = "/time/json")
or other permutations, I don't yet have proof of concept that the callbacks have been called at all.

/time/json returns a value like '{"time": 1273522247.674603}' as application/json; when it was not debugged and gave an error page, it didn't get the error callback.

Suggestions for what I should be doing differently? I'd really like to know how to use $.ajax() like this even if I usually use something higher-level.

Jonathan Hayward