Ajax.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. use think\Lang;
  5. /**
  6. * Ajax异步请求接口
  7. * @internal
  8. */
  9. class Ajax extends Frontend
  10. {
  11. protected $noNeedLogin = ['lang', 'upload'];
  12. protected $noNeedRight = ['*'];
  13. protected $layout = '';
  14. /**
  15. * 加载语言包
  16. */
  17. public function lang()
  18. {
  19. header('Content-Type: application/javascript');
  20. header("Cache-Control: public");
  21. header("Pragma: cache");
  22. $offset = 30 * 60 * 60 * 24; // 缓存一个月
  23. header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
  24. $controllername = input("controllername");
  25. $this->loadlang($controllername);
  26. //强制输出JSON Object
  27. $result = jsonp(Lang::get(), 200, [], ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]);
  28. return $result;
  29. }
  30. /**
  31. * 上传文件
  32. */
  33. public function upload()
  34. {
  35. return action('api/common/upload');
  36. }
  37. }