ArtlyticalMedia ArtlyticalMedia - 1 year ago 176
jQuery Question

Fat-Free Framework + JQuery AJAX GET = no response

I have a mapped Fat-Free Framework class declared as follows in my


$f3->map('/user', 'User');

class looks like this:

class User {
function __construct($f3) {
$this->users = new \DB\SQL\Mapper($f3->db, 'users');

function get($f3) {
return json_encode('Just some text');

function post($f3) {
// There is tested, working code in here but I've omitted it for simplicity's sake

function put($f3) {

function delete() {

I have my Javascript first loaded by app.js like this:

var currentPage = $(location).attr('pathname'),
requiredJS = document.createElement('script'),
requiredJS.type = 'text/javascript';

switch(currentPage) {
case '/mypage':
requiredJS.src = 'myscript.js';
// more cases...

Then my simple AJAX call in
looks like this:

$.get('/user', function (data) {

When I go to the
route, I get only an empty string in my console. Why is this happening? Where am I messing up?

Answer Source

You should echo the result:

echo json_encode(array('Just some text'));