0
考慮下面的JavaScript代碼:ASP.NET AJAX頁面方法不一致
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);
}
,並在後面的我的代碼給出下面的頁面方法:
[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();
}
}
jQuery的AJAX方法調用偶爾返回'錯誤:200 OK'。
錯誤的罕見自然使我相信,我的Web服務器「在一個糟糕的狀態被」,以及(無論何種原因)不能服務於傳入的請求。
據我所知,'錯誤:200 OK'可能表示返回的內容格式不正確,不符合指定的contentType。雖然這一切都很好,但我需要理解爲什麼我的代碼可能會定期受到這種情況的影響。
任何人都可以協助嗎?