Javascript 文本区域中的换行符未在来自数据库的文本中解释
我在iFrame中的文本区域中有一个“ajaxed”的文本(源代码来自同一个网站) 如果我直接将内容设置为我尝试过的函数之一的参数,那么效果很好,可以解释换行符,但在使用保存来自MySQL数据库的数据的变量时就不行了 正如我在stack上的几篇文章中看到的那样,我尝试了多种方法,但没有任何效果Javascript 文本区域中的换行符未在来自数据库的文本中解释,javascript,html,jquery,ajax,iframe,Javascript,Html,Jquery,Ajax,Iframe,我在iFrame中的文本区域中有一个“ajaxed”的文本(源代码来自同一个网站) 如果我直接将内容设置为我尝试过的函数之一的参数,那么效果很好,可以解释换行符,但在使用保存来自MySQL数据库的数据的变量时就不行了 正如我在stack上的几篇文章中看到的那样,我尝试了多种方法,但没有任何效果 let content = $('#myFrame').contents(); // Get the content of the iFrame let description = response.d
let content = $('#myFrame').contents(); // Get the content of the iFrame
let description = response.description; // Ajax data : text
content.find('#description').val('foo\r\nbar'); // Works
content.find('#description').html('foo\r\nbar'); // Works
content.find('#description').text('foo\r\nbar'); // Works
content.find('#description').val(description); // Doesn't work
content.find('#description').val(String(description)); // Doesn't work
content.find('#description').html(description); // Doesn't work
content.find('#description').html(String(description)); // Doesn't work
content.find('#description').text(description); // Doesn't work
根据要求,我添加了更多的信息,但是我不能把所有的HTML,有很多东西
MySQL中该特定行的表设置:
姓名:description
类型:文本
排序规则:utf8\U通用\U ci
php脚本使用mysqli检索数据:
$description = $row['description'];
$arrayAr['description'] = $description;
然后将数据作为JSON发送到jquery:
echo json_encode($arrayAr);
jQuery的ajax部分:
function ajaxStuff(link, num) {
$.ajax ({
url: link,
type: "POST",
data : {id: num},
dataType: "json",
cache: false,
success: function(response) {
let content = $('#myFrame').contents();
// the rest of this code is in the snippet above
}
HTML、实际页面和使用iFrame调用的页面都具有UTF-8字符集:
<iframe src='../forms/form2.php'
id='myFrame'
frameborder='0'
width=''
height='800'
scrolling=''
></iframe>";
”;
欢迎使用SO。您也可以添加html代码吗?谢谢@RayeesAC。我已经添加了更多信息。如果还有其他有用的信息,请告诉我。