Visualizzazione dei risultati da 1 a 2 su 2

Visualizzazione discussione

  1. #1
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,508

    [jQuery/Json] qualcosa nella stringa causa un errore

    Tramite jQuery invio una chiamata AJAX al server che risponde con una stringa in formato JSON fatta così
    codice:
    {
    	"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"
    }
    Questo è esattamente ciò che ritorna dalla chiamata, ho messo un semplice alert senza processare la stringa

    Il codice jQuery che uso per la ricezione e parsing della stringa è questo
    codice:
    $.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);
    	},
    });
    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 JSON
    { "html_code":"Prova", "height":"523px" }

    Tutto funziona correttamente, nel div appare "Prova".

    Cossa c'è che non va nella stringa contenente il codice html?
    Ultima modifica di Alhazred; 02-12-2013 a 20:06

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.