将其他数据从ajax帖子保存到cakephp控制器

时间:2015-07-24 19:19:56

标签: php jquery ajax cakephp

我从表中获取数据,我希望POST并在我的控制器功能上接收数据,这很好,现在如果我尝试保存数据,则会给我一个错误:

JS:

        $('#bot_guar').click( function () {
        //var rows = $("#tabla1").dataTable().fnGetNodes(); 

        var oTable = $('#tabla1').dataTable();
        var dat = oTable.fnGetData();
        var t=dat;
        //alert(t[0][0]);
        $.ajax({
        type:"POST",
        dataType: 'json',
        url: "<?= Router::Url(['controller' => 'cab_facturas', 'action' => 'addDetFac'], TRUE); ?>/",//teacher//getdata/3
        data:{value_to_send:JSON.stringify(t)}, 
        success: function(data){    
            alert(data+'the data was successfully sent to the server');
        }//success
        });     

    }); 

控制器;

class CabFacturasController extends AppController {
var $uses = array('CabFactura', 'DetFactura','Dosificacion','Articulo');
public $helpers = array('Html','Form','Js'=>array('Jquery'));
    public function addDetFac() {

       $this->autoRender = false;
       if( $this->request->is('post')) {
         // echo $_POST['value_to_send'];
        $array=json_decode($_POST['value_to_send']);
        $data = array(
            'DetFactura' => array(
                'cab_factura_id' => $array[0][0],
                'cab_factura_id_agencia' => $array[0][1],
                'articulo_id' => $array[0][2],
                'cantidad' => $array[0][4],
                'precio' => $array[0][5],
                'monto' => $array[0][6],
                'nro_lote' => $array[0][7],
            )
        );
        $this->DetFactura->create();
        $this->DetFactura->save($data);
        echo $data['DetFactura']['cab_factura_id'];
        //die();
        }
}

}

邮件错误: POST http://localhost/cake/facturacion/cab_facturas/addDetFac/ 500(内部服务器错误)

此时我可以显示我发送的数据,但是当我添加时我不能。请帮助我。

0 个答案:

没有答案