-1
我需要帮助。 我正在做一个webmethod在asp.net,但我总是收回消息“无法加载资源:服务器响应状态500(内部服务器错误)”webmethod asp.net状态500(内部服务器错误)
我的服务器我有这个代码(我的代码遗憾的质量较差,但it's首次在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