问题描述
我在iFrame内的文本区域中获得了“ ajax”的文本(来源来自同一网站)。
如果我直接将内容设置为我尝试过的函数之一的参数,则它可以正常工作并且换行符可以被解释,但是当使用包含来自MySQL数据库的数据的变量时则不能。
我已经尝试了多种方法,如我在堆栈中的几篇文章中所见,但没有任何效果。
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中的表设置:
名称:说明
类型:文本
整理:utf8_general_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>";
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)