我正在嘗試使用$ http向我的服務器發送獲取請求。我有一個WebMethod,看起來像這樣:
[WebMethod]
[ScriptMethod(UseHttpGet = true,
ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
public static IList<EmailContentModel> GetEmailContents(int emailTemplateID, int? pageIndex, int? pageSize)
{
var clientManagementRepository = GetClientManagementRepository();
var emailContents = clientManagementRepository.GetEmailContents(emailTemplateID, pageIndex, pageSize);
return emailContents;
}
當我使用POST方法(和改變的WebMethod到UseHttpGet = FALSE)以下返回正確的數據。
function getEmailContentDetails(pageIndex) {
return $http({
method: "POST",
url: "EmailContent.aspx/GetEmailContents",
data: JSON.stringify({ emailTemplateID: emailTemplateID, pageIndex: pageIndex, pageSize: pageSize }),
headers: { 'Content-Type': "application/json; charset=utf-8" }
}).then(onSuccess, onError);
}
但是,當我使用GET方法
function getEmailContentDetails(pageIndex) {
return $http({
method: "GET",
url: "EmailContent.aspx/GetEmailContents",
params: { emailTemplateID: 3, pageIndex: 1, pageSize: 10 }
headers: { 'Content-Type': "application/json; charset=utf-8" }
}).then(onSuccess, onError);
}
它屬於過去,在頁面的完整HTML源代碼返回給我,而不是正確的數據。我使用SQL分析器查看,當我使用GET時,數據庫甚至沒有被請求命中。當我使用ajax時,我可以使用GET並且工作正常。
嘗試刪除標題:{'Content-Type':「application/json; charset = utf-8」} – Steve
@Steve仍然沒有好史蒂夫。 – Mathemats
你得到了什麼HTML?錯誤頁面或404頁面? – Steve