5
Json'u çıkaran bir PHP'ye sahibim.PHP tarafından üretilen JSON dizgisinde çıktı HTML
{"titel":"Here comes the title","html":"<strong>Here is the HTML<\/strong>\n<br \/>\n<br \/>\n And some more."}
Ve jQuery/Ajax olacaktır:
<?php
$html = utf8_encode($gegevens['tekst']);
$html = htmlentities($html);
//$html = htmlspecialchars($gegevens['tekst'], ENT_QUOTES, 'UTF-8');
echo json_encode(array('titel' => $gegevens['titel'], 'html' => $html));
?>
çıkışı gibi olacak
$.ajax({
type: "GET",
url: "content/popup.php?id=" + id2,
dataType: 'json',
crossDomain: true,
success: function(json) {
var titel = json['titel'];
var html = json['html'];
function ContentTonen()
{
// Div's legen van content
$('.popup_home_head_inside').empty();
$('.popup_home_content_inside').empty();
$('.popup_home_head_inside').html(titel);
var html2 = html.replace(/\"/g, "");
//$('.popup_home_content_inside').html(html2);
$('.popup_home_content_inside').html(html2);
Ve HTML çıktısı: Öyleyse
<strong>Some HTML</strong> <br /> Some more text.
HTML olarak işlemez.
Bana yardımcı olabilir misiniz?
nasıl sonra JSON için html hazırlanabilirim: htmlentities dönüştürecektir
gösterecektir html dahil
için? Stripslashes çalışmıyor. – DaanNe tür bir hazırlık yapmak istiyorsun? – Jithesh
HTML'yi doğrudan JsonEncode'a eklediğimde, null değerini döndürür. Çünkü geçerli bir JSON değil. Htmlentities ile JsonEncode dizeyi geçerli JSON olarak kabul etti. Ancak HTML'yi geçerli JSON olarak hazırlamak için hangi işlevi kullanmalıyım? – Daan