doufei7464 2018-07-04 02:10 采纳率: 0%
浏览 72
已采纳

在运行过程中的codeigniter中的空白屏幕

I am developing a php script using codeigniter framework. My script is performing a heavy data loading process at the beginning of the script. I have used a gif in order to avoid displaying a blank screen for user until it completes the backend process. However, I noticed the gif I have used within the view won't display until all of the other processes are completed which is useless.

Is there anyway that I can run a preloading screen until other processes are completed? If so how can I do this?

I tried adding the page which contains gif at the top (before running all of the other processes) But still no luck, it loads everything along with the other views only.

Thanks in advance

MY CODE AS FOLLOWS,

SCRIPT

 <script>
        $(window).load(function() {
        //alert("IN");
        $.ajax({
        method :'GET',
        url: baseUrl+'main/LoadAllitems',
        //type: "GET",
        success:function(data){
        $('.se-pre-con').hide();
        $('#renderer').html(data);
        },
        error:function (){}
        });
    });
    </script>

CONTROLLER

public function LoadAllitems()
    {

        $MenuData['searches']=$this->get_search_form_data();
        $MenuData['dailydeals']=$this->get_daily_deals_data();
        //$MenuData['monthlydeals']=$this->get_monthly_deals_data();
        //$MenuData['featuredproducts']=$this->get_featured_products_data();

        $response=$this->load->view('includes/search',$MenuData,TRUE);
        echo $response;
        $response2=$this->load->view('homepage/dailydeals',$MenuData);
        echo $response2;
        //$this->load->view('homepage/mainslider',$MenuData);
        //$this->load->view('homepage/monthlydeals',$MenuData);
        //$this->load->view('homepage/feature',$MenuData);
        //$this->load->view('homepage/subscribe',$MenuData);
        //$this->load->view('main',$MenuData);

    }

INDEX

public function index()
    {
    $this->load->view('main',$MenuData);
  }

</div>
  • 写回答

1条回答 默认 最新

  • dsmnedc798226 2018-07-04 02:22
    关注

    Load the page initially with the gif then when the page loaded. run a script that request an ajax call to request the data you needed. btw we can help lot more if you provide your code: view and controller.

    SampleController.php

    function index()
    {
       $this->load->view('init_view');
    }
    
    function ajax_load_data()
    {
       ...
       $response = $this->load->view('some_view',$data,TRUE);
       echo $response;
    }
    

    init_view.php

    <div id="loading">SOMEGIF</div>
    <div id="renderer"></div>
    
    <script>
    
     $(document).ready(function(){
             $.ajax({
                 method : 'get',
                 url    : '<?php echo site_url("samplecontroller/ajax_load_data");?>'
                 success: function(responce){
                        $('#loading').hide();
                        $('#renderer').html(responce);
                     }   
             })
    
       })
    
    </script>
    

    some_view.php

    <h1><?= $title ?></h1>
    <p><?= $intro ?></p>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!