Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Ajax + Elefant

edited April 2013 in Framework

That problem is SOLVED AND WORKING

When i load page by ajax, dynamic content like gallery or slideshow , shows only {! filemanager/slideshow?path=design/sponsorzy !}
HTML result is not rendering, all other content is OK.

JS for ajax


xhr = jQuery.ajax({  
        scriptCharset: "utf-8" , 
            contentType: "application/json; charset=utf-8",
                type: "GET",
                url: '/blog/ajax/'+'?type='+type+'&id='+addres[3],

..............

My handler for ajax calls is:


<?php
/**
 * Displays a single blog post or a page from ajax call.
 */
$page->layout = false;
header ('Content-Type: application/json');
    $type    = $_GET['type'];
    $id      = $_GET['id'];
    if($type=='blog'){
        $posts = blog\Post::query ()
        ->where ('published', 'yes')
        ->where ('id', $id)
        ->fetch (2);
            $json = array(
            'body' => $tpl->run_includes ($posts[0]->data['body']),
            'title' => $posts[0]->data[title], 
            'ts' => $posts[0]->data[ts],
            'published' => $posts[0]->data[published],
            'tags' => $posts[0]->data[tags], 
            'author' => $posts[0]->data[author]
            );
            echo json_encode($json);
}
    if($type=='page'){
        $posts = Webpage::query ()
        ->where ('title', (string)$id)
        ->fetch (1);
            $json = array(          
            'body' => $tpl->run_includes ($posts[0]->data['body']),
            'title' => $posts[0]->data[title], 
            'ts' => $posts[0]->data[ts],
            'published' => $posts[0]->data[published],
            'tags' => $posts[0]->data[tags], 
            'author' => $posts[0]->data[author]
            );
            echo json_encode($json);    
            
}?>  

Is there a way to render content from page?

Comments

  • edited April 2013

    Just reformatting to make your code a bit easier to follow:

    JS for ajax:

    xhr = jQuery.ajax({
        scriptCharset: "utf-8" , 
            contentType: "application/json; charset=utf-8",
                type: "GET",
                url: '/blog/ajax/'+'?type='+type+'&id='+addres[3],
    
    .....
    

    Handler:

    <?php
    /**
     * Displays a single blog post or a page from ajax call.
     */
    $page->layout = false;
    header ('Content-Type: application/json');
        $type    = $_GET['type'];
        $id      = $_GET['id'];
        if($type=='blog'){
            $posts = blog\Post::query ()
            ->where ('published', 'yes')
            ->where ('id', $id)
            ->fetch (2);
                $json = array(
                'body' => $posts[0]->data[body], 
                'title' => $posts[0]->data[title], 
                'ts' => $posts[0]->data[ts],
                'published' => $posts[0]->data[published],
                'tags' => $posts[0]->data[tags], 
                'author' => $posts[0]->data[author]
                );
                echo json_encode($json);
    }
        if($type=='page'){
            $posts = Webpage::query ()
            ->where ('title', (string)$id)
            ->fetch (1);
                $json = array(          
                'body' => $posts[0]->data[body], 
                'title' => $posts[0]->data[title], 
                'ts' => $posts[0]->data[ts],
                'published' => $posts[0]->data[published],
                'tags' => $posts[0]->data[tags], 
                'author' => $posts[0]->data[author]
                );
                echo json_encode($json);    
    
    }?>  
    
  • I see what you mean. You'll want to pass the body through $tpl->run_includes() like this:

    'body' => $tpl->run_includes ($posts[0]->data['body']),
    
  • thank you :)

  • edited April 2013

    Thank's everything is working:)

Sign In or Register to comment.