Friday, October 19, 2012

RE: Render Element with AJAX Request / Response

Thanks,

 

That does work!

$view_output = $this->render('add')->body());

 

But I also found another way.

 

$html_view = new View($this, false);

$view_output = $html_view->render('add');

 

Is there a difference in either in terms of processing the request? Is 1 more efficient over the other?

 

Thanks,

Dave

 

From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of majna
Sent: Friday, October 19, 2012 8:46 AM
To: cake-php@googlegroups.com
Subject: Re: Render Element with AJAX Request / Response

 

Hi,

Controller::render() returns CakeResponse object, so try

'html' => $this->render()->body()


On Friday, October 19, 2012 2:56:44 AM UTC+2, advantage+ wrote:

My original function to return a JSON array no longer works with v2.1.3

 

This worked in 1.3: loaded a form into a modal window

 

Controller code snip:

if ( empty( $this->data ) ) {

                $this->data = $record; //debug shows the $record so there is data / debug is at 0 now

                $response = array(

                                'status' => true,

                                'title' => $record['Education']['program'],

                                'html' => $this->render());

}

                                                               

$this->_ajaxReturn( $response ); //simply encodes and returns the $response echo json_encode($response);

 

But the html data is no longer being rendered into the JSON response. The fancybox loads but no HTML.

 

The js for the ADD link in the view calls this js:

$(".add").live('click', function (){

                                $.fancybox.showActivity();

                                $.ajax({

                                                type: "GET",

                                                url: $(this).attr("href"),

                                                cache: false,

                                                resetForm: true,

                                                dataType: 'json',                                              

                                                success: function(r) {

                                                                $.fancybox({

                                                                                                'autoDimensions'             :               false,

                                                                                                'opacity' : 1,

                                                                                                'width' : 740,

                                                                                                'margin' : 10,

                                                                                                'padding' : 10,

                                                                                                'content' : r.html});

                                                               

                                                               

                                                               

                                                }

                                });

                                return false;                      

                });

 

 

The JSON response looks like this:

{"status":true,"title":"Auto Generated For Development","html_view":{}}

 

Any ideas?

 

Thanks,

Dave

 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: