Pergunta

Dado o seguinte código javascript:

    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);
}

, com o seguinte método de página no meu código por trás:

    [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();
        }
    }

O método JQuery AJAX invocação ocasionalmente 'Erro: 200 OK' retorna.

A natureza pouco frequente dos erros me leva a crer que o meu servidor web "fica em mau estado", e (por qualquer motivo) é incapaz de atender as solicitações recebidas.

Pelo que entendi, 'Erro: 200 OK' pode significa que o conteúdo retornado é mal formado e não se conforma com o contentType especificado. Enquanto isso é tudo muito bem, eu preciso entender por que meu código pode ser periodicamente suscetíveis a esta condição.

Alguém pode ajudar?

Foi útil?

Solução

Métodos de página são não inconsistente.

Mas uma string de consulta pode variar 'window.location.href'.

Esta página será sempre referência ao mesmo arquivo code-behind, então não há nenhuma razão para se apoiar 'window.location.href'. Eu posso código rígido o nome da página em seu lugar.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top