is it possible to be able to do without a view for a cakephp controller function? i am trying to have my server return a datatype that is not a string - but an array
my controller function :
function test() {
$this->layout = 'plain';
$task['Numbers']['uno'] = 'mooo';
$task['Numbers']['dos'] = 'says the cow';
$result = json_encode($task);
$this->set('result', $result);
}
my view file test.ctp
echo $result;
my jquery:
$('#test').live('click', test);
function test() {
var data = $('#form').serialize();
$.ajax({
type: "post",
url: "/controller/test",
data: data,
dataType: 'json',
success: function(response){
alert(response.Numbers.uno);
}
});
}
clicking on the html element marked test doesn't give me anything. however if i take out
dataType: 'json',
and change
alert(response.Numbers.uno);
to
alert(response);
in my jquery - i get an alert: the json encoded data but as a string (
alert(typeof response);
)
does anyone have any idea what might be happening?