无脂框架+ JQuery AJAX GET =无响应

时间:2016-07-19 17:56:29

标签: javascript php jquery ajax fat-free-framework

我在index.php

中声明了一个映射的Fat-Free Framework类
$f3->map('/user', 'User');

User类看起来像这样:

<?php
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() {
  }
}

我首先通过app.js加载我的Javascript:

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

  switch(currentPage) {
    case '/mypage':
      requiredJS.src = 'myscript.js';
      $('body').append(requiredJS);
      break;
    // more cases...
  }
});

然后我在mypage.js中的简单AJAX调用如下所示:

$.get('/user', function (data) {
  console.log(data);
});

当我转到/mypage路线时,我的控制台中只有一个空字符串。为什么会这样?我搞砸了哪里?

1 个答案:

答案 0 :(得分:1)

你应该回应结果:

SELECT CAST(CollectionDate as DATETIME) + CAST(CollectionTime as DATETIME)
FROM field