0
如果函數GetTest返回值,一切正常,否則錯誤。我該如何妥善處理空洞的承諾?我試過,但我得到:如何處理空承諾
無法加載資源:服務器500(內部服務器錯誤)的狀態迴應
getTest = function (testId)
{
var promise = $http(
{
method: 'POST',
url: self.baseUrl + 'Test/getTest',
contentType: 'application/json',
data: {
testId: testId
}
});
return promise;
}
[HttpPost]
public ActionResult getTest(string testId)
{
JsonResult jsonResult = new JsonResult();
try
{
Test model = new Test();
string returnValue = model.GetTest(Convert.ToInt32(testId));
if(!string.IsNullOrEmpty(returnValue))
{
jsonResult.Data = returnValue;
Response.StatusCode = 200;
return jsonResult;
}
else
{
Response.StatusCode = 500;
return Content("NoResult");
}
}
catch (Exception ex)
{
return jsonResult;
}
}
你是什麼意思「空承諾」。您的狀態碼爲500(「服務器錯誤」),將被視爲錯誤。你問你如何處理錯誤? – JLRishe