Ajax.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\shop\controller;
  3. use app\common\controller\Frontend;
  4. use Think\Cache;
  5. use think\Lang;
  6. /**
  7. * Ajax异步请求接口
  8. * @internal
  9. */
  10. class Ajax extends Frontend
  11. {
  12. protected $noNeedLogin = ['lang'];
  13. protected $noNeedRight = ['*'];
  14. protected $layout = '';
  15. /**
  16. * 加载语言包
  17. */
  18. public function lang()
  19. {
  20. header('Content-Type: application/javascript');
  21. $callback = $this->request->get('callback');
  22. $controllername = input("controllername");
  23. $this->loadlang($controllername);
  24. //强制输出JSON Object
  25. $result = jsonp(Lang::get(), 200, [], ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]);
  26. return $result;
  27. }
  28. /**
  29. * 上传文件
  30. */
  31. public function upload()
  32. {
  33. return action('api/common/upload');
  34. }
  35. function clearcache()
  36. {
  37. rmdirs(CACHE_PATH, false);
  38. rmdirs(TEMP_PATH, false);
  39. Cache::clear();
  40. $this->success('执行完毕');
  41. }
  42. }