2009-08-11 27 views
0
$.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 

Le code ci-dessus ne m'avertit pas l'ID. pourquoi .... Mon code de contrôleur est commeMessage Ajax ne renvoyant pas la valeur du contrôleur cakephp

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

Et mon save_form.ctp a

<?php 
    $data = array(); 
?> 

<?php 
    foreach ($formid as $r): 
     array_push($data, array(
      'id' => $r['Form']['id'] 
     )); 
    endforeach; 
    echo json_encode(array(
     "forms" => $data 
    )); 
?> 
+0

Vous pourriez aller plus loin avec ceci sur StackOverflow –

+0

quelle version de cakephp vous utilisez? –

Répondre

0

essayer avec

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 />"; 
} 

pour voir ce qui est disponible en POST et GET array

Questions connexes