javascript - Ajax call of php function does not send json array -
this javascript calls php function through ajax json datatype. data returned php should json array 3 items: html, todays_events, debug_text. on linux json returned isn't array. last item, debug_text returned, response['html'] null.
this 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 created html added in 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 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'] created 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 returned 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 javascript side response["html"] , response["todays_events"] contain "null". these contain html text. doesn't json_encode handle html?
Comments
Post a Comment