Tramite jQuery invio una chiamata AJAX al server che risponde con una stringa in formato JSON fatta così
Questo è esattamente ciò che ritorna dalla chiamata, ho messo un semplice alert senza processare la stringacodice:{ "html_code": "<div class='event-preview' > <a href='http://www.sito.it/events/show/9/event-9'> <span class='event-titolo-preview'>Event 9</span> </a><br /> <img src='http://www.sito.it/static/upload/image.gif' alt='image' class='event-img-preview' /><br /> Roma (RM) <br /><br /> Inizio: 21/11/2013 10:00<br /> Fine: 21/11/2013 18:00<br /><br /> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam... <a href='http://www.sito.it/events/show/9/event-9'><br />leggi tutto</a> </div>", "height":"523px" }
Il codice jQuery che uso per la ricezione e parsing della stringa è questo
Il problema è che se arriva la stringa JSON indicata sopra, nel div "events-of-the-day" non ci viene messo niente, in pratica deve esserci un qualche errore, se invece faccio arrivare la string JSONcodice:$.ajax({ url: "<?php echo base_url('home/events_of_the_day/') ?>", type: 'POST', data: form_data, success:function(response) { var json_obj = jQuery.parseJSON(response); var events=json_obj.html_code; var height=json_obj.height; $('div#events-of-the-day').html(events); $("div#nano_events").css("height", height); }, });
{ "html_code":"Prova", "height":"523px" }
Tutto funziona correttamente, nel div appare "Prova".
Cossa c'è che non va nella stringa contenente il codice html?

Rispondi quotando