1 ajax_example_progressbar.inc ajax_example_progressbar_progress($time)

Get the progress bar execution status as JSON.

This is the menu handler for examples/ajax_example/progressbar/progress/$time.

This function is our wholly arbitrary job that we're checking the status for. In this case, we're reading a system variable that is being updated by ajax_example_progressbar_callback().

We set up the AJAX progress bar to check the status every second, so this will execute about once every second.

The progress bar JavaScript accepts two values: message and percentage. We set those in an array and in the end convert it JSON for sending back to the client-side JavaScript.

Parameters

int $time: The timestamp.

See also

ajax_example_progressbar_callback()

File

modules/examples/ajax_example/ajax_example_progressbar.inc, line 66
Progress bar example.

Code

function ajax_example_progressbar_progress($time) {
  $progress = array(
    'message' => t('Starting execute...'),
    'percentage' => -1,
  );

  $completed_percentage = tempstore_get('ajax_example', 'progressbar_' . $time);

  if ($completed_percentage) {
    $progress['message'] = t('Executing...');
    $progress['percentage'] = $completed_percentage;
  }

  backdrop_json_output($progress);
}