bug^君 2015-11-25 20:18 采纳率: 25%
浏览 12

将AJAX移至服务器

Right now I have HTML blocks that involve a script to call data from another DB (outside of concrete5) and I've been using XHTTP Posts to retrieve the data.

The problem: The scripts currently exist on the client side (e.g. you can see it by inspecting element) and I think it is being called from the client's device. Once I close down access to that external DB, this won't work anymore. I need these requests to come from my website and not the client.

The need: I know there is a way to move these requests to within Concrete5, so that concrete5 is making the requests and not the client. I'm just not sure how to go about doing this. Any advice would be really appreciated.

  • 写回答

1条回答 默认 最新

  • weixin_33725270 2016-12-21 10:19
    关注

    You could do this by creating an end point.. which is an address on your website that returns data when called.

    so for example calling

    www.domain.com/api/getusers{id}
    

    Could return a JSON object for users.

    A quick example.

    in your application/bootstrap/app.php file you can add.

    Route::register(
      '/api/getusers/{id}',
      'application\Controller\endpoints::getUsers'
    );
    

    Then you add a controller in application/controllers/endpoints.php

    <?php
    namespace Application\Controller;
    
    use Concrete\Core\Controller\Controller;
    use \Concrete\Core\Http\Request;
    
    class Endpoints extends Controller {
    
        /* Get all a Regions Expeditions */
    
        public function getUsers()
        {
          $id = Request::getInstance()->get('id');
          $userid = $th->sanitize($id);
    
                /* Do something with $id */
    
          echo json_encode($output);
        }
    }
    ?>
    

    More info can found here http://c5hub.com/learning/ajax-57-style/

    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接