I am trying to show online train in my page without any refresh.So i think i have to use javascript to do this .so i am so beginner in javascript .so let me explain my problem .
I have to execute this part of code using javascript:
<%
OnlineTrainList = TimeTableRepository.GetAll().ToList();
foreach (var t in OnlineTrainList)
{
Response.Write("<div id='train-box' style='margin-left:"+(t.XTrainLocation-8)+"px;margin-top:"+t.YTrainLocation+"px;background:"+t.Train.TrainColor+"'>" +
"<span>" +
t.TrainId +
"</span>" +
"</div>");
List<Sensor> PassedSensor = new List<Sensor>();
PassedSensor = SensorRepository.FindBy(i => i.CurrentTrainId == t.TrainId).ToList();
string color = TrainRepository.FindBy(i => i.Id == t.TrainId).First().TrainColor;
foreach (Sensor sensor in PassedSensor)
{
Response.Write("<div class='CurrentColor-Sensor' style='margin-left:" + (sensor.XLocation-1 ) + "px;margin-top:" + (sensor.YLocation+8) + "px;background:" + color + "'></div>");
}
}
%>
This code every time is refreshed and get the online train positon and show that on the page ,but i have to do this with javascript.
So i create a .asmx file like this :
namespace ShirazRailWayWeb.Service
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class SiteLocationService : System.Web.Services.WebService
{
public TimeTableRepository TimeTableRepository = new TimeTableRepository();
public SensorRepository SensorRepository = new SensorRepository();
public List<TimeTable> OnlineTrainList = new List<TimeTable>();
public TrainRepository TrainRepository = new TrainRepository();
[WebMethod]
public string myfunc()
{
}
}
}
my problem is how can i pass list of value to javascript .i should load my data in َُ**asmx** file and call this function in my page .But i don't know how can i pass a list of array online train list to my page .
Here is my repository that generate the data .but this data is a list and i don't know how can i pass this data to my page.!!
public TimeTableRepository TimeTableRepository = new TimeTableRepository();
public SensorRepository SensorRepository = new SensorRepository();
public List<TimeTable> OnlineTrainList = new List<TimeTable>();
public TrainRepository TrainRepository = new TrainRepository();
Any idea.
best regards