[英]C# JQuery, Load data in webform and pass it to another webform
I'm making a "Ping" (ICMP) web application and I need to show the time results of the ping in a graph (I'm using shieldui). 我正在制作“ Ping”(ICMP)Web应用程序,并且需要在图形中显示ping的时间结果(我正在使用shieldui)。 I'm really new to web development and so my knowledge on the frameworks is limited.
我真的是Web开发的新手,所以我对框架的了解有限。
In "ping.aspx", I am loading a list of the servers I want to be able to ping. 在“ ping.aspx”中,我正在加载我希望能够ping的服务器列表。 When I press a button labelled "ping", the web application will ping all the servers and then open a new window with a single graphic per each server.
当我按下标有“ ping”的按钮时,Web应用程序将对所有服务器执行ping操作,然后打开一个新窗口,每个服务器上都有一个图形。
It is working till the point of loading the graph in the new window 一直工作到在新窗口中加载图形为止
Here is my grafica.aspx file: 这是我的grafica.aspx文件:
$(".pingAll").click(function () {
primerClick = true;
$("#txtLista option").each(function () {
var valorSvr = $(this).val();
//var container = $("#contenedorChart");
//var grafics = container.find("div");
//var idGrafics = grafics.length + 1;
//container.append("<div id=shieldui-chart" + valorSvr + "></div>");
refreshListaServidores(valorSvr)
});
//window.location.href = 'graficas.aspx';
});
function refreshListaServidores(valorSvr) {
$("#txtLista option").each(function () {
var valorSvr = $(this).val();
var container = $("#contenedorChart");
var grafics = container.find("div");
var idGrafics = grafics.length + 1;
container.append("<div id=shieldui-chart" + valorSvr + "></div>");
});
lista = lista + "|" + valorSvr;
var data = {
vl: lista
}
$.ajax({
type: "POST",
url: "ping.aspx/valoresLista",
cache: false,
async: true,
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
var resultado = result.d
$.each(resultado, function (index, item) {
var resultPing = { items: [] };
var resultadoGrafica = { grafica: [null] };
$.each(item, function (inde, ite) {
var valMs = ite.ms;
var valServer = ite.servers;
var txtData = "Servidor: " + valServer + " | " + "Dirección: " + ite.address + " | " +
"Time to Live: " + ite.ttl + " | " + "Tamaño Buffer: " + ite.bufferSize + " | " +
"Tiempo en ms: " + valMs + "\n";
resultadoGrafica.grafica.push(valMs);
resultPing.items.push(txtData);
});
$("#txtResultPing").val(resultPing.items);
jQuery(function ($) {
$("div[id*='shieldui-chart" + valorSvr + "']").shieldChart({
axisX: {
axisType: 'linear',
ticksColor: 'yellow',
borderColor: 'yellow',
min: 1,
max: 40
},
theme: "dark",
primaryHeader: {
text: "Gráfico de: " + valorSvr
},
exportOptions: {
image: false,
print: false
},
dataSeries: [{
seriesType: "line",
collectionAlias: "Tiempos en ms",
data: resultadoGrafica.grafica
}]
});
});
});
}, error: function (result, xhr, ajaOptions, throwError) {
var vainaconvaina = result + xhr + ajaOptions + throwError;
}
});
}
and in back code, in c# I have 在后台代码中,在C#中,我有
[WebMethod]
public static List<List<dataResult>> valoresLista(string vl)
{
dataResult dataRes = new dataResult();
HttpContext.Current.Session["pingas"] = vl;
Ping ping = new Ping();
string contentLista = vl;
string[] contentListaArray = contentLista.Split('|');
List<dataResult> listaPing = new List<dataResult>();
List<List<dataResult>> listaGral = new List<List<dataResult>>();
foreach (string word in contentListaArray)
{
dataRes = new dataResult();
if (!string.IsNullOrEmpty(word.ToString()))
{
try
{
listaPing = new List<dataResult>();
for (int i = 1; i <= 40; i++)
{
dataRes = new dataResult();
ping = new Ping();
PingReply pingreply = ping.Send(word);
if (pingreply.Status == IPStatus.Success)
{
dataRes.servers = Convert.ToString(word);
dataRes.address += Convert.ToString(pingreply.Address);
dataRes.ms += Convert.ToInt32(pingreply.RoundtripTime);
dataRes.ttl += Convert.ToInt32(pingreply.Options.Ttl);
dataRes.bufferSize += Convert.ToString(pingreply.Buffer.Length.ToString());
dataRes.errr += "Successful";
}
else
{
dataRes.errr = Convert.ToString("Host de destino no disponible o inalcanzable");
}
listaPing.Add(dataRes);
}
}
catch (Exception err)
{
PingReply pingreply = ping.Send(word);
if (pingreply.Status == IPStatus.DestinationHostUnreachable || pingreply.Status == IPStatus.DestinationNetworkUnreachable || pingreply.Status == IPStatus.TimeExceeded || pingreply.Status == IPStatus.TtlExpired || pingreply.Status == IPStatus.Unknown)
{
string emailEnProceso = "Se le informa ";
emailEnProceso += Environment.NewLine;
emailEnProceso += Environment.NewLine;
emailEnProceso += "que el servidor " + vl;
emailEnProceso += Environment.NewLine;
emailEnProceso += Environment.NewLine;
emailEnProceso += "podría estar presentando fallos debido a que en el último minuto no estuvo respondiento las solicitudes de ping ";
emailEnProceso += Environment.NewLine;
emailEnProceso += "Tome las medidas necesarias. ";
emailEnProceso += Environment.NewLine;
emailEnProceso += Environment.NewLine;
emailEnProceso += "something";
emailEnProceso += Environment.NewLine;
emailEnProceso += "www.somethingelse.com";
string asunto = "Falla en el servidor " + vl;
enviarMail(emailEnProceso, asunto, "someEmail@gmail.com");
listaPing.Add(dataRes);
}
else
{
dataRes.errr = Convert.ToString(err.Message);
}
}
listaGral.Add(listaPing);
}
}
return listaGral;
}
I'm pretty sure this code is not that bad at all, but what I need to know is how to "move" the data from "ping.aspx" to "grafica.aspx". 我很确定这段代码并没有那么糟糕,但是我需要知道的是如何将数据从“ ping.aspx”“移动”到“ grafica.aspx”。
Maybe I am really close, but in fact I don't really understand how to organize myself between to webforms. 也许我真的很亲密,但实际上我并不真正了解如何在Web表单之间组织自己。
Thanks a lot. 非常感谢。
As far as I see from your code fragments, it seems to be ok. 据我从您的代码片段看,这似乎还可以。 But it depends what data you get on the post success.
但这取决于您获得成功的数据。 Also you do not need to create a new chart instance on each request, you just can refresh the existing instance.
同样,您无需在每个请求上都创建新的图表实例,只需刷新现有实例即可。 The whole app is needed though for detailed help.
尽管需要完整的应用程序才能获得详细帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.