开发者

updating a cakephp model field through jquery

i'm trying to update a the field of a cakePHP model through a jquery request.

eventhough the ajax call is a success , the model isn't updated on the database .

<?php $Url = Router::url(array('controller'=>'coupons','action'=>'update_statut'),true); ?>

  $.post('<?php echo $Url ?>', { id: id},function(data) 
      { alert("sucess");开发者_运维问答
    }).error(function() { alert("error"); })
        .complete(function() { alert("complete"); });

on the controller's side here's the action :

function update_statut(){
      Configure::write('debug', 0);
      $this->autoRender = false;
       if($this->RequestHandler->isAjax()) {
            $this->Coupon->id= $this->params['form']['id'];
            $this->Coupon->saveField('statut','terminé');
           }

i even hardcoded the id in the action to make sure it fits with my table row.

any suggestions


you might wanna check out if you u've done

var $components = array('RequestHandler');

might be the condition


i not a pro of cakephp but can you try to replace

$this->Coupon->id = $this->params['form']['id'];

by

$this->Coupon->id = $this->params['data']['id'];

?

you could find more info here.


firstble try to work with $.get like this :

<?php $Url = Router::url(array('controller'=>'coupons','action'=>'update_statut'),true); ?>

  $.get('<?php echo $Url ?>'+'/'+id, {},function(data) { 
          alert("sucess");
       });

and in function update_statut add the parameter id like this one:

function update_statut($id=null){
      Configure::write('debug', 0);
      $this->autoRender = false;
       if($this->RequestHandler->isAjax()) {
            $this->Coupon->id= $id;
            $this->Coupon->saveField('statut','terminé');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜