2017-10-11 78 views
-1

我已經在使用編輯器的mysql表中存儲了一些html代碼。它包含YouTube視頻的嵌入代碼,所以在mysql中列條目是這樣當從mysql獲取數據時,html標籤正在顯示

This is a hello text. <iframe width="560" height="315" src="https://www.youtube.com/embed/zAlX1V3lK5s"> </iframe><br> 

我想提出一個jQuery的GET調用從MySQL得到這個數據,我已經使用這個代碼是

$.get(
    'test.php', 
    function(response) { 
     console.log(response); 
     $('#test').html(response); 
    } 
); 

PHP代碼獲取結果是

mysql_connect("localhost", 'root', 'root'); 
mysql_select_db("dummy"); 

$rs = mysql_query("select dummy from demotable where id = xyz"); 
$r = mysql_fetch_array($rs); 

echo $r['dummy']; //contains that string which includes iframe too 

但是當我顯示結果的DIV那麼它是不是有顯示視頻,但它顯示的字符串,因爲它是我在前端獲取輸出格是

This is a strong beer. <iframe width="560" height="315" src="https://www.youtube.com/embed/zAlX1V3lK5s"> </iframe><br> 

我怎樣才能得到視頻,而不是顯示源?

+0

從[tag:php-5.5]開始,不推薦使用'mysql_ *'。所以改爲使用'mysqli_ *'或'PDO'。 [爲什麼我不應該在PHP中使用mysql_ *函數?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189#14110189) – mega6382

+0

它只是一個例子,我正在使用蛋糕的PHP做的事情,但它仍然顯示字符串,而不是將嵌入代碼轉換爲視頻 –

回答

-1

我認爲你需要強制加載iframe。根據What’s the best way to reload/refresh an iframe?這可以用JavaScript來實現這樣的:

document.getElementById('some_frame_id').contentWindow.location.reload();

但是,這可能會是這樣的jQuery中:

$('#test').find('iframe')[0].contentWindow.location.reload();

試一下:)

+0

這並不能解決問題。也是
標籤正在顯示,它應該在那裏換行。所以這是與php的變量有關。因爲如果直接插入這樣的文字,則可以使用$('#test')。html('This is a text。