I am working on a CakePHP 2.x app and trying to implement JSONP. It's my first time, so I don't know how can I do this:
$(function(){
$.getJSON("https://www.example.com/myweb/api/getjsonp&jsoncallback=?",
function(data){
console.log(data);
}
);
});
Controller:
public function getjsonp(){
$id = $this->Auth->user('idUser');
$messages = $this->Contact->getMessages($id);
$totalmessages = json_encode($messages);
echo $_GET['jsoncallback'] . '(' . $totalmessages . ')';
}
The code isn't working. Am I missing something?