Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This javascript calls a php function through ajax with json datatype. The data returned from php should be a json array with three items: html, todays_events, debug_text. On linux the json returned isn't an array. Only the last item, debug_text is returned, response['html'] is null.

This is the ajax call.

    $.ajax({
    url: "get_events.php",
    type: "POST",
    data: { user_id: user_id, todays_only: todays_only },
    dataType: 'json',
    cache: false,
    async: false,
    success: function (response) {
        if (response != '') 
        {
            if ( trim(response["html"]) != "" ) {
              var scroll_5_html = response["html"];
              $("#scroll_5").html(scroll_5_html);

            }
            else {
              var filter_select = document.getElementById("filter_today").checked;
              if ( filter_select == true ) {
                noevents_text += "<br/>for today";
              }
              $('#scroll_5').html('<p style="width: 140px; padding-top: 140px; padding-bottom: 131px; margin:0 auto; font-family: \'Trebuchet MS\'; font-size:12px; color:white;">'+noevents_text+'.</p>');               
            }

            todays_events = response["todays_events"];
        }
    },
    error: function (request, status, error) {
        /* alert ("status "+status+" error "+error+" responseText "+request.responseText); */
    },
});    

#

The $print_html variable is created with HTML added in this way

    $print_html = '';
    $print_html .= '<div id="'.$node['id'].'" class="channel event" source="'.$node->source.'" channel_id="'.$channel_id.'" start_date="'.$start_date.'" onclick_string="'.$onclick.'"><a>'.$print_first.'</a></div>';

    $print_span = $node->title.'<br/>'.$start_date;

    if (isset($event_time) && $event_time != "" ) {
        $print_span .= ' '.$event_time.'<br/>';
    }
    $print_span .= 'Source: '.$site;
    if ( isset($node->notes) && $node->notes != "" && $node->notes != "null" ) {
        $print_span .= '<br/>'.'Notes: '.$node->notes;
    }

    $print_html .= "<script type='text/javascript'>
    var channel_top = $('.channel:last').position().top + 110;
    $('#matting').append('<span id=\"tv".$node['id']."\" class=\"tooltip\" style=\"top:'+channel_top+'px;\">".$print_span."</span>');
    </script>\n";

The todays_events variable is an array.

$todays_events = array();

if ( $event_added_flag != 1 ) {
                                    $event_array[$nodeid.'_'.$iatt] = $todays_print_date.' '.strtolower($r_string);
                                    $start_dates[$nodeid.'_'.$iatt] = $todays_print_date;
                                    $event_times[$nodeid.'_'.$iatt] = $r_events[$iat];
                                    array_push($todays_events, $nodeid.'_'.$iatt);
 }

The other variable $return['debug_text'] is created as shown before.

    $return['debug_text'] .= ' r_at '.$r_at.' r_events count '.$events_count;
    $return['debug_text'] .= ' start_date '.$start_date.' print_date '.$print_date.'<br/>';

#

The data is returned from the php as

$return['html'] = $print_html;
$return['todays_events'] = $todays_events;
$return['debug_text'] .= '\r\nfilter flag '.$todays_only;

echo json_encode($return);
return;

On the javascript side response["html"] and response["todays_events"] contain "null". These contain html text. Doesn't json_encode handle html?

share|improve this question
1  
We need to see more JavaScript and PHP, such as $print_html, $todays_events, and $return['debug_text'], when they are defined. –  PHPglue Apr 25 at 1:19
    
'\r\nfilter flag ' should be "\r\nfilter flag ". That's just literal r and n. –  PHPglue Apr 25 at 1:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.