Код: Выделить всё
[WebMethod]
public static string List(String codeConstruction, String code, String searchText, String from, String to, String const)
{
DateTime dateFrom = nUtil.RetornaDataAntiga();
DateTime dateTo = nUtil.RetornaDataFutura();
var custActive = const == "1";
if (!String.IsNullOrEmpty(de))
{
try
{
dateFrom = DateTime.Parse(de);
}
catch (Exception)
{
dateFrom = nUtil.RetornaDataAntiga();
}
}
if (!String.IsNullOrEmpty(ate))
{
try
{
dateTo = DateTime.Parse(ate);
}
catch (Exception)
{
dateTo = nUtil.RetornaDataFutura();
}
}
if (!custActive)
{
var dayFilter = 365;
if ((String.IsNullOrEmpty(code))
&& (String.IsNullOrEmpty(codeConstruction))
&& (String.IsNullOrEmpty(searchText))
&& ((dateTo - dateFrom).TotalDays > dayFilter))
{
return nUtil.RespostaJson(new { mensagem = "Not Enough Filters" }, 400);
}
}
List lst = new List();
using (var db = new dbModule())
{
lst = db.ListThings()
}
return nUtil.RespostaJson(lst);
}
< /code>
Это метод, который создает ответ: < /p>
public static String RespostaJson(T objeto, int statusCode = 200)
{
if (statusCode == 0)
{
statusCode = 500;
}
HttpContext.Current.Response.StatusCode = statusCode;
return JsonConvert.SerializeObject(objeto);
}
< /code>
frontend ajax call
и мой вызов такой: < /p>
javascript < /p>
$.ajax({
type: "POST",
url: url,
contentType: 'application/json; charset=utf-8',
data: options.body ? JSON.stringify(options.body) : null,
dataType: 'json',
success: (data, status, xhr) => {
if (!data.d) {
response = { data: "", error: null, status: xhr.status };
} else {
const obj = JSON.parse(data.d);
response = { data: obj, error: null, status: xhr.status };
}
if (options.popupOnSuccess) {
showFastAlertWithStatus(response);
}
return resolve(response);
},
error: (xhr, status, error) => {
if (xhr.status > 499) {
response = { data: null, error: xhr.responseJSON, status: xhr.status };
}
else {
if (!xhr.responseJSON) {
response = { data: null, error: { mensagem: status }, status: xhr.status === 200 ? 500 : xhr.status };
}
else if (!xhr.responseJSON?.d) {
let errorObj = xhr.responseJSON;
if (!xhr.responseJSON?.mensagem && xhr.responseJSON?.Message) {
errorObj = { mensagem: xhr.responseJSON?.Message }
}
response = { data: null, error: errorObj, status: xhr.status };
}
else {
const obj = JSON.parse(xhr.responseJSON.d);
response = { data: null, error: obj, status: xhr.status };
}
}
if (options.popupOnError) {
showFastAlertWithStatus(response);
}
return resolve(response);
}
});
Ответ, который я хочу (случается в разработке):
Подробнее здесь: https://stackoverflow.com/questions/797 ... production