Search code examples
phpcakephpfetchcakephp-2.1

PHP Fetching Data in the Background


We are building an Analytics App. Which will need the user to wait for 30 seconds while we fetch the data from another source and do some calculations before displaying it to the user.

Is there any way we can show a waiting page to the user while we fetch the data in the background rather than have the page load for 30 seconds as we fetch the data.

Can any one throw some light on how it can be done ?


Solution

  • Note : for lightbox, you have to include lightbox js

         <script>
        function onload_wating()
        {
        var syncronize_target=SITE_URL+'your_controllername/action_timer/';
    
        $.lightbox(syncronize_target, {
                    width   : 450,
                    height  : 260,
                    'modal' : true,
                    'onOpen'  : function() {    
                        $(".jquery-lightbox-button-close").css({"visibility":"hidden","display":"none"});
                    }
                });
          }
    
        onload_wating();
        <script>
    

    action_timer.ctp

    Note : for countdown,you have to include jquery countdown -> http://keith-wood.name/countdown.html

         <script>
         $(function () {    
            $('#syncronize_header_timer').countdown(
                    {
                    until:+50,
                    format: 'MS',
                    onExpiry: ltliftOff
                    }); 
        });
    
            function ltliftOff() {
    
                $.lightbox().close();
            }
    
        <script>
     <div id="syncronize_header_timer" ></div>
    

    ==========================================

    Above onload_wating() this function open lightbox and make ajax query to ur controller action and open action_timer.ctp

    in action_timer.ctp, we use countdown timer . This timer count to 50, then its automatically close.

    between this 50 second , you can retrive ur data from database.