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));
?>