Php echo显示br标签

时间:2014-03-05 21:59:25

标签: javascript php jquery html line-breaks

我有一个HTML表单。单击“提交”按钮时,它会将框中的数据存储到表中,然后显示一条消息。消息从PHP文件发送,然后由js在HTML文件中显示。问题是邮件中包含br个标记,当邮件显示时,它会显示<br>标记,而不是破坏该行。

这是我正在测试的地方 - http://ft5.cu.cc/点击心形徽标查看表格。

HTML表格

<div class="contact">
            <form method="post" action="daalo.php">
                <input type="text" maxlength="30" class="text" name="ign" id="ign" placeholder="Please type your IGN(In Game Name)" required="required"/>
                <input type="email" maxlength="30" class="required email" name="email" id="email" placeholder="Please type your email" required="required"/><span class="status"></span>
                <table width="100%">
                <tr>
                <td><input type="text" maxlength="30" class="text" id="steamid" name="steamid" placeholder="Enter your Steam ID" required="required"/></td>
                <td><span class="status">
                <img id="tick" alt="Good"src="images/tick.png" width="16" height="16"/></td>
                </tr>
                </table>
                <span id="cross">Steam Id Already Added</span>
                </span>
                <input type="submit" name="register" id="register" value="Submit" disabled="disabled" />
            </form>
            <div id="loading">Processing your <b>WHITELIST</b> entry....</div>
        <div id="success"></div>
    </div>

* Php Insert *

<?php
include('connecti.php'); //Ganja Login


 // Check connection
 if (mysqli_connect_errno())
   {
   echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
   }

//Insert
$lab1='IGN<br>'; 
$lab2='Email ID<br>'; 
$lab3='Steam ID<br>';
$lab4='Submitted.';
$lab5='Whitelist is updated everyday at 8pm (UTC+01:00) Brussels, Copenhagen, Madrid, Paris.';

$sql="INSERT INTO rusty_whitelist (name, email, steamid) VALUES ('$_POST[ign]','$_POST[email]','$_POST[steamid]')";

 if (!mysqli_query($con,$sql))
   {
   die('Error: ' . mysqli_error($con));
   }
    echo $lab1;
    echo $lab2;
    echo $lab3;
    echo $lab4;
    echo $lab5;

 mysqli_close($con);
 ?>

Java脚本

(function($) {
$('form').submit(function(e){
    var thisForm = $(this);
    e.preventDefault();
    $(this).fadeOut(function(){
        $("#loading").fadeIn(function(){
            $.ajax({
                type: 'POST',
                url: thisForm.attr("action"),
                data: thisForm.serialize(),
                success: function(data){
                    $("#loading").fadeOut(function(){
                        $("#success").text(data).fadeIn();
                     });
                }
            });
        });
    });
});
$('.md-trigger').tipsy({gravity: 's'});
})(jQuery);

$(function(){
  $().ready(function() {
    $('#videobg').tubular({videoId: 'tDvBwPzJ7dY'}); // where idOfYourVideo is the YouTube ID.
  });
});

2 个答案:

答案 0 :(得分:1)

我认为问题在于如何将Ajax返回的值用于代码中。不要使用jQuery .text()方法,请尝试使用.html()方法。

答案 1 :(得分:1)

正如我在评论中所怀疑的那样,您通过jQuery的textContent property设置元素对象的text() method(或DOM等级2)。

您需要调用html() method来设置innerHTML属性(或等效属性)。