I am working on an API using Phalcon. I am in the trial/error phase learning both Phalcon and the proper way to build a REST API using this framework.
My issue is that when making an ajax call via jQuery to my API with type: "GET" Phalcon is not able to parse the request using getJsonRawBody. When I run the same ajax call via jQuery with type: "POST" it works.
Here is my ajax request.
$('.start').click(function() { var arr = {timestamp:'<?=time();?>'}; $.ajax({ type: "GET", beforeSend: function (request) { request.setRequestHeader("X-Api-Key", "<?=$api_key;?>"); request.setRequestHeader("X-Hash", "<?=$hash;?>"); }, data: JSON.stringify(arr), contentType: 'application/json; charset=utf-8', url: "https://api-dev.fancompetition.com/my-rest-api/api/robots/", }) .done(function(data) { $('#data').html(data); }); });
On the server side I have:
$vars = $app->request->getJsonRawBody();
So now if you change type to POST I am able to get the contents. When type is GET than my variable vars is blank. Any idea as to why?