views:

71

answers:

2

I'm using ajax to do some validation on some dates passed (basically making sure that the first date/time occurs before the 2nd date/time, and neither are blank).

If I have async set to true, it works, but I get a false positive because it's working at the same time as the rest of my form validation. If I set it to false, then I get an error along the lines of "XMLHttpRequest Exception 101".

I'm just wanting to know what causes this error and how does one get rid of it (while keeping async set to false). I do have other options to get around it, but I'd rather know what it is and how to fix it.

example querystring ?action=validate_dates&start_date=12/12/2009 21:00:00&end_date=12/12/2009 23:00:00&rsvp_start=11/21/2009&rsvp_end=11/30/2009

Will return either "" or a comma seperated list of fields that should be marked bad.

function validate_event()
{ 

 $.ajax({
  type: "POST",
  url: "company_event_ajax.php",
  data: querystring,
  dataType: "text",
  async: false,
  error:function (xhr, ajaxOptions, thrownError)
  {
   alert(thrownError);
  },
  success: function(msg)
  {
   if (msg == "")
   {
    $("#event_start_date,#event_end_date,#rsvp_start_date,#rsvp_end_date").css("background-color", "#fff");
   }

   else
   {
    var errs = msg.split(',');
    for (i = 0; i < errs.length; i++)
    {
     $("#"+errs[i]).css("background-color", "#fcc"); 
    }
    disable = true;
   }
  }
 });

 if (disable) return false;
 else return true;
}

This is not the first time this is happening. I'd like to know exactly what causes the 101 error to come about and how to avoid it/fix it.

A: 

example querystring ?action=validate_dates&start_date=12/12/2009 21:00:00&end_date=12/12/2009 23:00:00&rsvp_start=11/21/2009&rsvp_end=11/30/2009`

This example querystring includes spaces. Perhaps this is your problem? Spaces (among other characters) are not allowed in URLs; you should use the JavaScript escape() function on parameter values (such as 12/12/2009 23:00:00) which will turn space characters to %20

intgr
Edited as you said, here is the declaration of the variable:var querystring = 'action=validate_datesThis still returns the same error. Still a good idea, though.
Joel Doetsch
A: 

I'm thinking it has something to do with expired/invalid server certificates on the test server I'm using. The function seems to work 100% when I test it on the live server. I'll go ahead and chalk it up to that.

Thanks

Joel Doetsch