We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

using of ajax with php

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

3
Contributors
3
Replies
1 Month
Discussion Span
1 Month Ago
Last Updated
19
Views
Question
Answered
amit.chaudhari.71
Newbie Poster
6 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

SPeed_FANat1c
Posting Pro in Training
496 posts since Apr 2010
Reputation Points: 13
Solved Threads: 17
Skill Endorsements: 0

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();
  });

});
lambing
Junior Poster in Training
76 posts since Feb 2010
Reputation Points: 10
Solved Threads: 15
Skill Endorsements: 0

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

amit.chaudhari.71
Newbie Poster
6 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Month Ago by lambing and SPeed_FANat1c

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0676 seconds using 2.7MB