嗨,我的 asp 中有一个代码可以从 mysql 数据库请求几个小时
C# 代码
string cmd = "SELECT DepartureTime FROM dbtest";
MySqlCommand mycmd = new MySqlCommand(cmd, conn);
MySqlDataReader dataReader = mycmd.ExecuteReader();
while (dataReader.Read())
{
times += dataReader.GetString(0) + "\n";
}
dataReader.Close();
Javascript
function SendForm() {
PageMethods.ConnectDatabase(OnSucceeded, OnFailed);
function OnSucceeded(msg) {
var vierkant = document.getElementById("Vierkant");
var context = vierkant.getContext('2d');
context.font = '15pt Calibri';
context.fillStyle = 'blue';
context.fillText('Departure Times bus X19:' + msg, 150, 100);
}
当我在我的 javascript 中调用此函数时,它会将所有时间都放在一行中
我喜欢在每个结果后休息一下
我怎样才能解决这个问题?
谢谢
我尝试了以下但仍然没有工作
我的画布或变量“msg”有问题吗?
Javascript:
var msg;
function Connect() {
PageMethods.ConnectDatabase(OnSucceeded, OnFailed);
function OnSucceeded(msg)
{
//Set context + Formatting
var context = document.getElementById("canvas").getContext('2d');
context.font = '15pt Calibri';
context.textAlign = "center";
context.textBaseline = "top";
context.fillStyle = 'blue';
//Prepare textarea value to be drawn as multiline text
var textval = msg.value;
var textvalArr = toMultiLine(textval);
var linespacing = 25;
var startX = 0;
var startY = 0;
//Draw each line on canvas.
for (var i = 0; i < textvalArr.length; i++) {
context.fillText(textvalArr[i], x, y);
y += linespacing;
}
}
//Create an array where the <br/> tag splits the values.
function toMultiLine(text) {
var textArr = new Array();
text = text.replace(/\n\r?/g, '<br/>');
textArr = text.split("<br/>");
return textArr;
/*var vierkant = document.getElementById("canvas");
var context = vierkant.getContext('2d');
//formatting
context.font = '15pt Calibri';
context.fillStyle = 'blue';
context.fillText('Departure Times bus X19:' + msg, 150, 100);*/
}
function OnFailed(error) {
alert("failed");
}
}
HTML:
<form id="Form1" runat="server">
<input type="button" onclick="return Connect()" value="Bushours:" />
<canvas id="canvas" width="1900" height="200">Test<code><canvas></code> element.
</canvas>