我想将 C# 中的自定义错误设置为显示而不是xhr.responseText
现在的默认错误。如何传递cSharpErrorMessage
给ajax错误?
这是我的 C# 代码:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static AjaxResult<string> GetAutoCompleteHtml(string termList)
{
const string cSharpErrorMessage = "Unable to generate autocomplete HTML.";
try
{
//some logic
}
catch (Exception ex)
{
//some logic
}
}
这是我的ajax函数:
function StartAutoCompleteSearch(termsList) {
if (termsList.length > 2) {
$.ajax({
url: '/Ajax/AjaxCalls.aspx/GetAutoCompleteHtml',
type: 'POST',
data: "{'termList':'" + termsList + "'}",
global: false,
datatype: JSON,
success: function(response) {
//some logic
},
error: function(xhr, response) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message + " Click OK to log back in ");
window.location = "/login";
}
});
}
}