Php 从MySQL(使用ajax)检索的数据超过了目标元素定义的宽度
我正在使用ajax调用从Mysql检索数据 这是Javascript文件:Php 从MySQL(使用ajax)检索的数据超过了目标元素定义的宽度,php,mysql,ajax,database,Php,Mysql,Ajax,Database,我正在使用ajax调用从Mysql检索数据 这是Javascript文件: var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("txt").innerHTML = this.responseText;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txt").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "sample.php?id=" + id, true);
xmlhttp.send();
这是sample.php文件
$id = $_GET['id'];
$query = "SELECT `description` FROM `products` WHERE `id`='$id'";
$query_run = mysql_query($query);
$description = mysql_result(query_run,0);
echo $description;
我已将目标“div”元素的宽度定义为500px。但从数据库生成的结果超过了500px。我希望每次宽度达到500px时,它都取下一行。请帮助我发生这种情况,因为描述中没有空格,我认为在真实描述中,word的大小永远不会超过500px。您可以尝试在DIV中添加一些CSS样式,例如,
单词break:always
,空白:wrap
,溢出wrap:break-word
。在找到完美的组合之前,你必须玩一点。