hi friends

i have develpoed a prog. for pay calculation for my office in php.
now i want to show some thing like employee name in my pge which is currently processing or progress bar with persent if calcution has done.
plz note i m useing POST methord

I have saved code snipped with flush:

PHP updating page when function is not finished
Tested, works. But does not work when fiddler is running.

public function index() {

        if (ob_get_level() == 0) {
            ob_start();
        }
        echo str_pad('Loading... ',4096)."<br />\n";
        $d = 0;
        for ($i = 0; $i < 25; $i++) {
            $d = $d + 11;
            $m=$d+10;
            //This div will show loading percents
            echo '<div class="percents">' . $i*4 . '%&nbsp;complete</div>';
            //This div will show progress bar
            echo '<div class="blocks" style="left: '.$d.'px">&nbsp;</div>';
            flush();
            ob_flush();
            sleep(1);
        }
        ob_end_flush();
    }

Clear screen when using this way of page updating:
private function clr_scr() {
        echo "<script type='text/javascript'>\n";
        echo "document.body.innerHTML = ''";
        echo "</script>";
    }

This is not ajax, but you can use it.

Not sure how this would work with ajax, havent' tried.

I'm not sure what you really want but try this.

In your JavaScript code, submit the name of your employee via form and perform an ajax call so as to not refresh the page.

Requirements:
jquery framework (widely used js framework that rocks!) - http://jquery.com/download/
jquery ujs so as to handle all ajax calls across your site - https://github.com/rails/jquery-ujs

HTML CODE:

<form action="youraction" method="post" id="form-id" "data-remote" => "true">
<input type="text" name="employee_name"/>
<div id="loader"></div>    
<button type="submit">Submit</button>
</form>

<div id="employee-data"></div>

JS CODE:

$(document).ready(function() {

  // ajax:before is executed upon submitting your form
  // you can insert a loader here or do some validation before sending your ajax call  
  $('#form-id').on('ajax:before', function() {
    // put your code here
    $('#loader').show();
  });

  // ajax:success runs when the server returns a successful call
  // display the data returned by your server here
  $('#form-id').on('ajax:success', function(event, data) {
    // put your code here
    // data depends on what kind of data your server responds (json or html format)
    $('#employee-data').html(data);

    // hide your loader
    $('#loader').hide();
  });

});

sorry to responce so late, my problem was solved through the code given by "SPeed_FANat1c"
but I would like to thanks to both of u along daniweb.com for the greate help . thank u to all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.