here is a simplification of how I make json requests  I am using jquery

views/layouts/ajax.ctp

    header('Content-Type: text/x-json');
    e(json_encode(Array('title' => $title_for_layout, 'content' =>
$content_for_layout)));

webroot/js/common.js

in a function that I attach to all links

function callAllLinks(dataURL)                   {
                $.getJSON(
                    dataURL,
                    function (json)    {
                        console.info(json);
                    }
                ); // /getJSON

}



                $("a")
                        .bind(
                            'click',
                            {'href': this.href,'rel': this.rel},
                            function(event)
                            {
                                 ...
                                event.preventDefault();
                                 callAllLinks(this.href);
                            }
                        );

hth - S

On 25/04/2008, Tomka <[EMAIL PROTECTED]> wrote:
>
>
> Hello.
>
> I try to get a JSON object as response of an AJAX request.
>
> The code in my view looks like this:
>
> echo $ajax->link("TEST",
>                 array("controller" => "mycontroller", "action" =>
> "myjsonview"),
>                 array("complete" => "testfunction(request, json);")
> );
>
> If I set the option "update" with an id of a div, I see the response:
> a well formatted JSON-Object - so "myjsonview" seems to be coded
> correctly. But how can a access this JSON-Object in my "complete"-
> function?
>
> Thanks for help!
>
>
> Tomka.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to