I have problem with AJAX in CakePHP. I have 2 different AJAX forms in one view. The first AJAX form works well, but the other one doesn't work properly. When I call the second AJAX, it doesn't set data from this form to $this->request->data
, but the AJAX will run properly. After that, it will update <div id="about"></div>
. Curious is fact, that after the div is updated and I try send data through this form again, it works and it will update my data in database. Also when I have only the second AJAX in the view, it will work properly and send the data first time I send the data through it.
Here's my code:
This is a view file:
<div id="price-list">
<?php echo $user['User']['price_list']; ?>
</div>
<?php
echo $this->Form->create('User');
echo $this->Form->input('User.price_list', array('label' => false));
echo $this->Js->submit('Save', array(
'url' => array('controller' => 'users', 'action' => 'ajax_edit_price_list'),
'update' => '#price-list',
'buffer' => false,
));
?>
<div id="about">
<?php echo $user['User']['about']; ?>
</div>
<?php
echo $this->Form->create('User');
echo $this->Form->input('User.about', array('label' => false));
echo $this->Js->submit('Save', array(
'url' => array('controller' => 'users', 'action' => 'ajax_edit_about'),
'update' => '#about',
'buffer' => false,
));
?>
I have also append <?php echo $this->Js->writeBuffer(); ?>
in my default.ctp before </body>
.
Do you have any idea, where can be a problem? Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…