Vwake
Vwake

Reputation: 171

cakephp elements and Ajax update

here is what i am trying to achieve...

i have a index view in which i have used the ajax helper not the cakephp one but an external one from http://www.cakephp.bee.pl/

i have succefully created an accordion using this helper.

now inside the accordion i have an addbutton which submits a form via ajax.

what i would like to do is when i submit the ajax form. i would also like to update the accordion. now the accordion is also created by using the ajax helper.

Can this be done without a page refresh

ajax submit form code :

    <div class="qnotesform">
<?php echo $this->Form->create('Qnote');?>
<ul class="qnotelist">
<li><?php   echo $this->Form->input('Qnote.subject', array('label'=>'Title', 'rows' => '1')); ?></li>
<li>    <?php   echo $this->Form->input('Qnote.body', array('label'=>'Header', 'rows' => '1')); ?></li> 
<?php   echo $this->Form->hidden('Qnote.user_id', array('value'=>Authsome::get('id'))); ?>
<?php   echo $this->Form->hidden('Step.0.user_id', array('value'=>Authsome::get('id'))); ?>
<li><?php   echo $this->Form->input('Step.0.body', array('label'=>'Steps' ,'class' => 'step',  'rows' => '1')); ?></li>
</ul>

<?php echo $ajax->submit(
'Submit', array(
'url' => array(
'controller'=>'qnotes',
'action'=>'add')
)); 

how can i achieve this . could someone please point me the right direction

another thing that i want to clear out is. If i want to be working one page . and all crud action to be used without a page refresh.

does anybody have a working example for the above senarios . or let me make it simple. how to refresh a div without refreshing the page.

Solution:

code

    <?php echo $ajax->submit('Submit', array(
'url'=> array(
'controller'=>'qnotes',
'action'=>'add'),
'update'=>'leftdiv',
'after'=>'$("#accordion").accordion({autoHeight: false, collapsible: true , header: "h3"});alert("after");',
)); 

however now I am facing another issue now, I am updating the accordion, everything works fine but as soon as update the accordion. the accordion loses its style class and stops working. I only see links then. any idea how.

Upvotes: 0

Views: 1797

Answers (1)

Gabriel Spiteri
Gabriel Spiteri

Reputation: 4978

It seems that one of the options in the array of the submit method is 'complete' which should allow you to trigger a js function that will update your accordion:

<?php echo $ajax->submit(
'Submit', array(
'url' => array(
'controller'=>'qnotes',
'action'=>'add',
'complete' => 'updateAccordian(request.responseText)')
));

the reuqest.responseText will contain the reponse from your controller/action.

HTH

Upvotes: 1

Related Questions