如何从数据库中获取数据时显示进度消息

时间:2020-03-03 08:32:16

标签: javascript php drupal-7 progress-bar drupal-modules

从数据库中获取数据时,我试图显示进度消息,因为获取值需要一些时间。如果表单正在处理中,我想向用户显示此进度消息。

我的.js文件:

(function ($) {
    $(document).ready(function(){
        $('#my-form-loading')
            .hide()  // Hide it initially
            .ajaxStart(function() {
                $(this).show();
            })
            .ajaxStop(function() {
                $(this).hide();
            });
    });
})(jQuery);

我的hook_menu:

$items['admin/config/network_drives/%/scan'] = array(
    'title'             =>  'Scan Network Drive',  //page title
    'description'       =>  'Scan a network drive',  //description show when mouse hover on link
    'page callback'     =>  'drupal_get_form',  //callback function which is invoked when menu item is called.
    'page arguments'    =>  array('_network_drive_scan'), //Module Form Function
    'type'              =>  MENU_LOCAL_TASK,
    'access callback'   =>  true,  //any user having add_network_drive can access this page
);

和我的功能:

function _network_drive_scan($form, &$form_state) {
    $arguments = arg();
    $id = $arguments[count($arguments) - 2];

    ini_set('max_execution_time', 0);
    require_once ('reader.class.php');
    require_once ('readerException.class.php');

    try{

        $query = db_select('network_drive','ndrive');
        $query
            ->fields('ndrive', array('ndid','username','password','host','path','type','algo'))
            ->condition('ndid',$id,'=')
            ->orderBy('ndrive.ndid');
        $results = $query->execute();

        $ND = $results->fetchAssoc();

        $reader = new Reader($ND); //DMS


        /**
         * Mysql query to insert network drive id into network drive listing table().
         */
        $arguments = arg();
        $id = $arguments[count($arguments) - 1];
        $query = db_select('network_drive','ndrive');
        $query
            ->fields('ndrive', array('ndid'))
            ->condition('ndid',$id,'=')
            ->orderBy('ndrive.ndid');
        $results = $query->execute();
        $network_drive_id = $results->fetchAssoc();

        /**
         * mysql query to fetch the directory name from path and insert into scanning process().
         */
        $directory_name = $arguments = arg();
        $networkdriveid = $arguments[count($arguments) - 2];
        $query = db_select('network_drive','networkd');
        $query
            ->fields('networkd', array('path'))
            ->condition('ndid',$networkdriveid,'=')
            ->orderBy('networkd.ndid');
        $results = $query->execute();
        foreach($results as $result){
            $array = explode("\\", $result->path);
            $networkpath =  isset($array[count($array) - 2]) ? $array[count($array) - 2] :   "Directory not available";
        }

        $array = $reader->scanFolder("",true);



        makeArrayFromNested($array,$networkdriveid,"root");

      $form['#prefix'] = '<div id="my-form-loading" style="display:none;">Loading..please wait>';
      $form['#suffix'] = '</div>';

        drupal_set_message(t('Network drive has been scanned successfully.'));

        $form_state['redirect'] = '/admin/config/network_drives';

      $module_path = drupal_get_path('module', 'nd');
      $element['#attached'] = array(
        'js' => array($module_path . '/page_load.js'),
      );

      return $element;

    }catch(ReaderException $e){

        die($e->message);

    }
}

我创建了“前缀,后缀,id”,并将它们传递到我的.js函数中,但没有任何反应。我在做什么错了?

0 个答案:

没有答案