$.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
上面的代码没有提醒我id。为什么这样.... 我的控制器代码就像
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);
}
我的 save_form.ctp 有
<?php
$data = array();
?>
<?php
foreach ($formid as $r):
array_push($data, array(
'id' => $r['Form']['id']
));
endforeach;
echo json_encode(array(
"forms" => $data
));
?>
答案 0 :(得分:0)
尝试
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 />";
}
查看POST和GET数组中的内容