在 DEV 上,错误(捕获)返回 application/json,但在 LIVE 上它是 text/html:
[WebMethod]
public static string UpdateCategoryProductDisplayOrder(int parentCategoryId, int productId, int displayOrder)
{
int rowsAffected = 0;
string message = string.Empty;
try
{
rowsAffected = DataAccess.CategoryProducts.UpdateCategoryProductDisplayOrder(parentCategoryId, productId, displayOrder);
message = rowsAffected.ToString();
}
catch (Exception ex)
{
HttpContext.Current.Response.StatusCode = 500;
message = ex.Message;
}
return message;
}
这是 jquery ajax 调用:
//Call the page method
return $.ajax({
type: "POST",
url: "WebMethods.aspx" + "/" + fn,
contentType: "application/json; charset=utf-8",
data: paramList,
dataType: "json",
success: successFn,
error: errorFn
});
我尝试将 catch 替换为:
catch(Excecption ex){ throw ex; }
它可以工作,但是有一个错误被忽略了。
任何帮助是极大的赞赏。提前谢谢你。