Visualizzazione dei risultati da 1 a 2 su 2

Discussione: json encode

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2012
    Messaggi
    31

    json encode

    Qualcuno sa quest'errore come posso risolverlo:

    The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol.


    return window.JSON.parse( data );

    dove la mia chiamata ajax è

    Codice PHP:
    function get_messages (){
                
    //alert(base_url+ "index.php/chat/ajax_get_message/"+ chat_id);
                
    $.ajax({
                                
    type"POST" ,
                                
    dataType"json" ,
                                
    urlbase_url "index.php/chat/ajax_get_message/" chat_id ,
                                
    success: function(data){
                                                        
    alert("1");
                                                        if (
    data.status == 'ok'){
                                                                 $(
    '#my_chat_view').html(data.content);
                                                                 
    alert("2");
                                                        }
                                                        
    alert("3");
                                         }
                }); 
                return 
    false;
            }
            
    get_messages(); 
    e il mio controller
    Codice PHP:
    function ajax_get_message($chat_id){
            
            
    $messages $this->chat_model->chat_get_messages($chat_id);
            
    $result = array('status'=>'ok','content'=> '');
            
    //header('Content-Type: application/x-json; charset=utf-8');        
                    //return json_encode($result);
            
    if ($messages->num_rows() > 0){
                
                
                
    $messages_html '<ul>';
                
                foreach (
    $messages-> result() as $mess){
                    
    $messages_html .= '[*]'$mess->message .'';
                }
                    
                
    $messages_html .= '[/list]';
                
                
    $result = array('status'=>'ok','content'=>$messages_html);
                
    //header('Content-Type: application/x-json; charset=utf-8');
                
    return json_encode($result);
                
            } 
            else{
                
    //header('Content-Type: application/x-json; charset=utf-8');
                
    $result = array('status'=>'ok','content'=> '');
                    
                return 
    json_encode($result);
            } 
    Ho provato a mettere i meta tag sopra l'header cosi

    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2012
    Messaggi
    31

    [Risolto]

    In realtà l'errore non aveva a che fare con il messaggio e non so perché mi appare. Si trattava di un attributo errato quando prelevavo dal database. Inoltre ho modificato la funzione facendo eseguire alla view il codice html e non dentro il controller che fa solo da tramite. Firebug non era sufficente a individuare il problema ho dovuto usare anche il debug. I due insieme mi davano il messaggio corretto. .

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.