Мне нужна помощь. Я делаю webmethod в asp.net, но я всегда получал сообщение «Не удалось загрузить ресурс: сервер ответил со статусом 500 (Internal Server Error)»webmethod asp.net статус 500 (Внутренняя ошибка сервера)
на моем сервере У меня есть этот код (извините плохое качество моего кода, но подмигнули первый раз в C# и ASP.NET)
`
public class nLinha
{
public string tipo { get; set; }
public string dataInicial { get; set; }
public string dataFinal { get; set; }
public string no { get; set; }
}
public class nLinhaResposta
{
public string stamp { get; set; }
public string documento { get; set; }
public string numero { get; set; }
public string nData { get; set; }
public string referencia { get; set; }
public string designacao { get; set; }
public string quantidade { get; set; }
public string vtotal { get; set; }
public string vunitario { get; set; }
}
[WebMethod]
public static string desenhaTabela(nLinha linha)
{
List<nLinhaResposta> resposta = new List<nLinhaResposta>();
//TDS ou de uma REF ?
if (linha.tipo != "REF")
{
GridView grdDados = new GridView();
grdDados.DataSource = MyCliente.GetConsumos(linha.no, Convert.ToDateTime(linha.dataInicial), Convert.ToDateTime(linha.dataFinal));
grdDados.DataBind();
foreach (GridViewRow row in grdDados.Rows)
{
nLinhaResposta x = new nLinhaResposta();
x.stamp = row.Cells[0].Text.ToString().Trim();
x.documento = row.Cells[5].Text.ToString().Trim();
x.numero = row.Cells[6].Text.ToString().Trim();
x.nData = row.Cells[4].Text.ToString().Trim();
x.referencia = row.Cells[1].Text.ToString().Trim();
x.designacao = row.Cells[2].Text.ToString().Trim();
x.quantidade = row.Cells[3].Text.ToString().Trim();
x.vtotal = row.Cells[7].Text.ToString().Trim();
x.vunitario = row.Cells[8].Text.ToString().Trim();
resposta.Add(x);
}
}
else
{
GridView grdDados = new GridView();
grdDados.DataSource = MyCliente.GetConsumos(linha.no, linha.tipo, Convert.ToDateTime(linha.dataInicial), Convert.ToDateTime(linha.dataFinal));
grdDados.DataBind();
foreach (GridViewRow row in grdDados.Rows)
{
nLinhaResposta x = new nLinhaResposta();
x.stamp = row.Cells[0].Text.ToString().Trim();
x.documento = row.Cells[5].Text.ToString().Trim();
x.numero = row.Cells[6].Text.ToString().Trim();
x.nData = row.Cells[4].Text.ToString().Trim();
x.referencia = row.Cells[1].Text.ToString().Trim();
x.designacao = row.Cells[2].Text.ToString().Trim();
x.quantidade = row.Cells[3].Text.ToString().Trim();
x.vtotal = row.Cells[7].Text.ToString().Trim();
x.vunitario = row.Cells[8].Text.ToString().Trim();
resposta.Add(x);
}
}
JavaScriptSerializer resultado = new JavaScriptSerializer();
return resultado.Serialize(resposta);
}
`
and in the client i have this
var obj = {};
obj.tipo = $("#tipo option:selected").val();
var from = $("#dataI").val().split("/");
var dataI = from[2]+"-"+from[0]+"-"+from[1];
var from1 = $("#dataF").val().split("-");
var dataF = from1[2]+"-"+from1[0]+"-"+from1[1];
obj.dataInicial = dataI.toString();
obj.dataFinal = dataF.toString();
obj.no = $("#cliente option:selected").val();
$.ajax(
{
url: "verConsumos.aspx/desenhaTabela",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify({ linha: obj }),
type: "POST",
success: function (data) {
console.log(data);
toastr.success("Sucesso ", "Sucesso", opts);
},
erro: function (XMLHttpRequest, textStatus, errorThrown) {
toastr.error("Erro com a operação", "Erro", opts);
}
});
Не добавлять irelevant или неправильные теги! – Olaf
Я не понял ваш ответ – jcunham