views:

355

answers:

1

Hi,

   $.ajax({
 type: "POST",
url: "http://localhost/FormBuilder/index.php/forms/saveForm/"+user_id,
datatype: 'json',
data: "formname="+formname+"&status="+status,
 success: function(json){
    alert( "id is : " + json.forms[0].id);
                        }//success
 });//ajax

The above code doesn't alerts me the id. why so.... My controller code is like

 function saveForm()
{
            //$userId=$this->Session->read('userId');
    $this->data['Form']['name']=$this->params['form']['formname'];
        $this->data['Form']['created_by']=$this->Session->read('userId');
        $this->data['Form']['status']=$this->params['form']['status'];
        $this->data['Form']['access']="Private";
        $userId=$this->Form->saveForms($this->data);
        $formid = $this->Form->find('all', array('fields' => array('Form.id'),
                                                            'order' => 'Form.id DESC'                                                                                                                   ));



        $this->set('formid',$formid);

}

And my save_form.ctp has

  <?php
 $data=array();

  ?>
 <?php foreach ($formid as $r): 


  array_push($data, array('id' => $r['Form']['id']));

endforeach; 

 echo json_encode(array("forms" => $data));

?>
A: 

try with

print "<br />POST<br />";
foreach ($_POST as $key => $value)
{
   print $key . " " . $value . "<br />";
}


print "<br />GET<br />";
foreach ($_GET as $key => $value)
{
   print $key . " " . $value . "<br />";
}

to see what comes in POST and GET array

andres descalzo