Hi,
I want to get such data using AJAX from PHP. With php I generate data this way:
$return['credits'] = $credits;
$return['banners'] = $this->generate_banners($user->id);
echo json_encode($return);
generate_banners:
function generate_banners($user_id)
{
$html = '';
$query = $this->db->where('user_id',$user_id)->select('filename')->get('jos_reklama_banners');
if($query->num_rows() > 0)
{
foreach($query->row() as $filename)
{
$html .= '<div id = "'.$filename.'">
<img src="'.base_url().'uploads/banners/'.$filename.'?'.time().'" />
</div>';
}
}
else $html .= 'Nėra banerių';
return $html;
}
So basically I want to get via ajax to values - credit amount and html code for banners.
In cliet side:
var obj = $.parseJSON(response);
$('p.credits').html('Jus turite kreditu: ' + obj.credits)
$('div.banners').html(obj.banners);
The problem is with banners html code. I get an error:
Uncaught Invalid JSON: {"credits":30,"banners":"<div id="\"file8.jpg\"">\n\t\t\t\t\t<img src="\"http:\/\/localhost\/joomla15\/uploads\/banners\/file8.jpg?1299779206\"" \="">\n\t\t\t\t<\/div>"}</div>
The html is not printed into page. How can I print it and remove that error?