简体   繁体   English

用外部php文件的结果填充jQuery Progress Bar

[英]Filling jQuery Progress Bar with results from an external php file

I am calling two php files throw jQuery and ajax. 我打电话给两个PHP文件抛出jQuery和Ajax。 I have a progress bar at the same page and I need to fill it with respect to the results of those two files. 我在同一页面上有一个进度条,我需要针对这两个文件的结果进行填充。 Like for example increase 10% after every function is executed. 例如,在每个功能执行后增加10%。

Progress bar in the main php file 主php文件中的进度栏

<meta charset="utf-8">
    <script>
    $(function() {
        $( "#progressbar" ).progressbar({
            value: 80
        });
    });
    </script>
 <div class="demo">

<div id="progressbar"></div>
</div>

Javascript which calls the external php files 调用外部php文件的Javascript

$.ajax({
        //    url: 'ajax/releaseBackEnd.php',
            url: 'batch/2-release-tmp.php',
            type: 'POST',
            async: false,
            data: {"fId":"abc"},
            dataType: 'xml',
            error: function(){
                alert('Error loading XML document1');
            },
            success: function(data){        
                //check error
                alert("success1");
                var $error=$(data).find('error1').text();
                if($error!="0")
                {
                    messageBox("Error1",$error);
                    return;
                }

            }
        });

External PHP file 2-release-temp.php 外部PHP文件2-release-temp.php

<?php

/*
 * script for releasing classification
 */


require_once(dirname(__FILE__) . "/../config.php");
require_once(TU_CLA_LIB . "/Database.php");


/* database */

$error = "";
$aDb = new Database();
if ($aDb->error) {
    print $aDb->error;
    exit;
}

/* build pathFacetsInfo for facets */

$res = $aDb->buildFacetsPath();
if (!$res) {
    print $aDb->error;
    exit;
}

/* build classification */
$res = $aDb->buildClassification();
if (!$res) {
    print $aDb->error;
    exit;   
}

print "release succeed.\n";


?>

This is not possible, you could split your php file and call each one of them. 这是不可能的,您可以分割您的php文件并分别调用其中的一个。 After the result of one php file you can increase your progress bar. 得到一个php文件的结果后,您可以增加进度栏。

Each call could look like this: 每个呼叫看起来像这样:

// buildFacetesPath.php
$.ajax({
  url: 'batch/buildFacetsPath.php',
  success: function(data){        
    var old = $("#progressbar").progressbar("value");
    $("#progressbar").progressbar("value", old+10)
  }
});

// buildClassification.php
$.ajax({
  url: 'batch/buildClassification.php',
  success: function(data){        
    var old = $("#progressbar").progressbar("value");
    $("#progressbar").progressbar("value", old+10)
  }
});

Your two php files could look like this: 您的两个php文件可能如下所示:

buildFacetesPath.php buildFacetesPath.php

<?php
/*
 * script for releasing classification
 */

require_once(dirname(__FILE__) . "/../config.php");
require_once(TU_CLA_LIB . "/Database.php");


/* database */

$error = "";
$aDb = new Database();
if ($aDb->error) {
    print $aDb->error;
    exit;
}

/* build pathFacetsInfo for facets */

$res = $aDb->buildFacetsPath();
if (!$res) {
    print $aDb->error;
    exit;
}

?>

buildClassification.php buildClassification.php

<?php
/*
 * script for releasing classification
 */

require_once(dirname(__FILE__) . "/../config.php");
require_once(TU_CLA_LIB . "/Database.php");


/* database */

$error = "";
$aDb = new Database();
if ($aDb->error) {
    print $aDb->error;
    exit;
}

/* build classification */
$res = $aDb->buildClassification();
if (!$res) {
    print $aDb->error;
    exit;   
}

print "release succeed.\n";

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM