title: Custom ajax error coming from C#
body: <p>I want to set custom error from C# to be displayed instead of <code>xhr.responseText</code> default as it is now.
  How to pass <code>cSharpErrorMessage</code> to the ajax error?</p>
  
  <p>Here is my C# code:</p>
  
  <pre><code>        [WebMethod]
          [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
          public static AjaxResult&lt;string&gt; GetAutoCompleteHtml(string termList)
          {
              const string cSharpErrorMessage = "Unable to generate autocomplete HTML.";
  
              try
              {
                  //some logic
              }
              catch (Exception ex)
              {
                  //some logic
              }
          }
  </code></pre>
  
  <p>Here is my ajax function:</p>
  
  <pre><code>function StartAutoCompleteSearch(termsList) {
      if (termsList.length &gt; 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";
              }
          });
      }
  } 
  </code></pre>