我正在开展一个项目,其中人工智能正在 MySQL 数据库上推送文本。然后,我们想在网页上显示正在进行的写作。我们仍在努力。
我们正在获取数据并定期检查数据库中的新条目。问题是,我们想用空格分隔每个文本并尝试使用 <br/>
或 <p>
但它不起作用,它似乎是“只是”文本并像这样显示。
我们的代码:
<head>
<script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style type="text/css">
#myTable{
width:"90%";
min-width: 250px;
word-wrap:break-word;
overflow:visible;
position:absolute;
border:solid 0px;
top:250px;
left:720px;
right:720px;
bottom:50px;
font-family:"Times New Roman", Times, serif;
text-align:justify
}
</style>
</head>
<body>
<div id="myTable"> <div>
<script type="text/javascript">
var skip = 0;
function get_data(index) {
$.ajax({
url : 'getData.php',
type : 'POST',
data: ({"skip":skip}),
success : function(data) {
if(data && data.trim()!='') {
skip = skip+1;
showText("#myTable", data, 0, 5);
}
else {
setTimeout(function () { get_data(skip); }, 30000);
}
},
error : function(request,error)
{
alert("Request error : "+JSON.stringify(request));
}
});
}
function showText(target, message, index, interval) {
if (index < message.length) {
$(target).append(message[index++]);
setTimeout(function () { showText(target, message, index, interval); }, interval);
}
else {
get_data(skip);
}
}
//var period = 10000; //NOTE: period is passed in milliseconds
get_data(skip);
//setInterval(page_refresh, period);
</script>
</body>
最佳答案
在 SQL 中,如果你将 CHAR(13)
连接到任何字符串,它会给你一个换行符。
DECLARE @textBreaking NVARCHAR(50)
SET @textBreaking = 'FIRST LINE.' + CHAR(13) + 'FIRST LINE.'
SELECT @textBreaking
选择此 block 将返回以下内容:
FIRST LINE.
SECOND LINE.
从 SQL 中获取文本并将其显示在网页上应该可以实现您的期望。
关于javascript - <br/> 不处理来自 mysql 查询的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45042304/