views:

254

answers:

1

Given the following javascript code:

 function ValidateFlagAsUrgent() {
  selectedValuesList = document.getElementById('<%= _searchResultsUserControlUserControl.SelectedValuesHiddenFieldClientID %>').value;
  $.ajax({
   type: 'POST',
   url: window.location.href + '/' + 'AreAnyOfTheSelectedTasksInMyProjects',
   data: '{"selectedTasks":"' + selectedValuesList + '"}',
   contentType: 'application/json; charset=utf-8',
   dataType: 'json',
   success: AjaxProjectManagerSucceeded,
   error: AjaxFailed,
   async: false
  });
 }

 function AjaxProjectManagerSucceeded(result) {
  if (result.d == true) {
   document.getElementById('<%= _variableWarningCioLabel.ClientID %>').innerHTML = '';
   document.getElementById('<%= _areAnyOfTheSelectedTasksInMyProjects.ClientID %>').value = 'true';
  }
  else {    
   document.getElementById('<%= _areAnyOfTheSelectedTasksInMyProjects.ClientID %>').value = 'false';
  }
 }

 function AjaxFailed(result) {   
  alert('Error: ' + result.status + ' ' + result.statusText);
}

and given the following Page Method in my code behind:

 [WebMethod]
 public static bool AreAnyOfTheSelectedTasksInMyProjects(string selectedTasks)
 {
  using (MyDataContext context = new MyDataContext())
  {
   IEnumerable<Guid> selectedTasksThatAreInMyProjects =
    from st in selectedTasks.Split('|')
    join t in context.Tasks
     on st equals t.Number.ToString()
    join pr in context.ProjectRepresentatives.Where(pr => pr.UserID == ContextHelper.CurrentUserID)
     on t.Request.ProjectID equals pr.ProjectID
    select t.ID;

   return selectedTasksThatAreInMyProjects.Any();
  }
 }

The JQuery AJAX method invocation occasionally returns 'Error: 200 OK'.

The infrequent nature of the errors leads me to believe that my web server "gets in a bad state", and (for whatever reason) is unable to service the incoming requests.

As I understand it, 'Error: 200 OK' may mean that the returned content is malformed and does not conform to the specified contentType. While that's all well and good, I need to understand why my code may be periodically susceptible to this condition.

Can anyone assist?

A: 

Page Methods are not inconsistent.

But a query string can vary 'window.location.href'.

This page will always reference the same code-behind file, so there's no reason to lean on 'window.location.href'. I can hard code the page name instead.

Jim G.