简体   繁体   English

回显包含来自MySQL的数据的HTML(空格)

[英]echo HTML that contains data from MySQL (whitespace)

I am trying to output a dynamic table, that works with JQuery 我正在尝试输出与JQuery一起使用的动态表

Just to get rid of the "" signs I tried declaring another variable: 为了摆脱“”符号,我尝试声明另一个变量:

$rowname = $row["name"];

And then have that row name saved in the data-bubble, which would be used by JQuery. 然后将该行名保存在数据气泡中,供JQuery使用。

echo '<tr id='.$current_row.' data-bubble={"part":"'.$rowname.'"}>';

The JQuery part: JQuery部分:

    var bubData=jQuery.parseJSON($(this).attr("data-bubble"));
    console.log(bubData);
    $("#bubbleTable b.part").text(bubData.part);

So when I have a 'name' entry (NoSpace) that has no spaces inside it, everything works: 因此,当我有一个“名称”条目(NoSpace),其中没有空格时,一切正常:

<tr id="1" data-bubble={"part":"NoSpace"}>

But whenever the name contains a space (Yes Space), this is what i get: Firefox: 但是只要名称包含空格(是空格),我就会得到:Firefox:

<tr id="2" Space"}="" data-bubble={"part":"Yes">

IE: IE:

<tr id="2" data-bubble='{"part":"Yes' Space"}="">

There has to be an easy way to get around this issue, but apparently my specialized English is not as good to find it myself. 必须有一种轻松的方法来解决此问题,但是显然我自己的专业英语并不擅长自己找到它。 (Have been searching for quite a while now. Not the right things, I guess.) (搜索已经有一段时间了。我猜这不是正确的东西。)

you forget the double quote in data-bubble and the browsers interpret the content in different ways. 您会忘记数据泡沫中的双引号,并且浏览器以不同的方式解释内容。

i suggest you to use printf/sprintf to format a string properly without double quote madness: 我建议您使用printf / sprintf正确格式化字符串,而不会引起双引号疯狂:

printf('<tr id="%d" data-bubble="{\'part\':\'%s\'}">', $current_row, $rowname);

output: 输出:

<tr id="1" data-bubble="{'part':'Yes Space'}>"

(based on comment) try to invert quoting to avoid problems: (基于评论)尝试反转报价以避免出现问题:

printf("<tr id='%d' data-bubble='{\"part\":\"%s\"}'>", $current_row, $rowname);

output: 输出:

<tr id='1' data-bubble='{"part":"Yes Space"}'>

忽略tr字符串:

echo '<tr id='.$current_row.' data-bubble="{\"part\":\"'.$rowname.'\"}";

在斜杠后使用单引号,例如'\\

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM