Javascript 使用AJAX在PHP文件中调用PHP方法

Javascript 使用AJAX在PHP文件中调用PHP方法,javascript,php,ajax,Javascript,Php,Ajax,现在,我有一个动态排序形式,允许用户选择类别、类型和子类型。这些信息将在PHP函数中使用(希望如此)。所有这些都在一个PHP文件中 我希望使用AJAX调用该PHP文件中的函数。我见过从HTML文档中使用AJAX调用PHP文件的方法,但不是从PHP文档中调用 这是我的configs.php的相关部分: <?php use FW\Config; require_once 'setup.php'; function build($category, $type, $subtype){ /

现在,我有一个动态排序形式,允许用户选择类别、类型和子类型。这些信息将在PHP函数中使用(希望如此)。所有这些都在一个PHP文件中

我希望使用AJAX调用该PHP文件中的函数。我见过从HTML文档中使用AJAX调用PHP文件的方法,但不是从PHP文档中调用

这是我的
configs.php
的相关部分:

<?php
use FW\Config;
require_once 'setup.php';

function build($category, $type, $subtype){
   //WANT TO GET HERE
}

function getTypes($dir) {
    return array_diff(scandir($dir), array('..', '.'));
}

function getSubTypes($dir, $type) {
    return array_diff(scandir("$dir//$type"), array('..', '.'));
}

function getVersions($dir, $type, $subType) {
    return array_diff(scandir("$dir//$type//$subType"), array('..', '.'));
}

function getFileContents($dir, $type, $subtype, $file){
    $path = "$dir/$type/$subtype/$file.txt"; 
    $openFile = fopen($path, "r"); 
    $content = fread($openFile, filesize($path)); 
    fclose($openFile);
    return split("/", $content)[0];
}

$project_dir = Config::$appConfig['project_file_dir']['scriptPath'];
$workflow_dir = Config::$appConfig['workflow_file_dir']['scriptPath'];

$project_types = getTypes($project_dir);
$project_subtypes = array();
$project_versions = array();

$workflow_types = getTypes($workflow_dir);
$workflow_subtypes = array();
$workflow_versions = array();

foreach ($project_types as $type) {
    $project_subtypes[$type] = getSubTypes($project_dir, $type);

    //@todo remove once folder structure is all setup
    if ($type !== 'CD') continue;

    foreach ($project_subtypes[$type] as $subType) {
        $project_versions[$subType] = getVersions($project_dir, $type, $subType);
    }
}

foreach ($workflow_types as $type) {
    $workflow_subtypes[$type] = getSubTypes($workflow_dir, $type);

    foreach ($workflow_subtypes[$type] as $subType) {
        $workflow_versions[$subType] = getVersions($workflow_dir, $type, $subType);
    }
}

function makeInfoSection($type, $subType, $versions, $dir) {    

    // list versions
    $html .= '<h4>Available Versions</h4>';
    $html .= '<ul class="list-group">';
    foreach ($versions as $v) {
        if (strpos($v, '.txt')) continue;

        $html .= '<li class="list-group-item">';
        $html .= '<span class="badge"><a href="#" style="color:orange">';
        $html .= '<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"';
        $html .= 'onclick="build()">'; //@todo add onclick to trigger build()
        $html .= '</span></a></span>';
        $html .= $v;
        $html .= '</li>';
    }
    $html .= '</ul>';

    return $html;
}

function makeSection($parent, $prefix, $type, $subTypes) {
    $headingID = 'heading-'.$type;
    $bodyID = 'collapse-'.$prefix.$type;

    $html = '<div class="panel panel-default" style="margin-bottom:10px;">';
    $html .= '<div class="panel-heading" role="tab" id="'.$headingID.'">';
    $html .= '<h4 class="panel-title">';
    $html .= '<a role="button" data-toggle="collapse" data-parent="'.$parent;
    $html .= '" href="#'.$bodyID.'" aria-expanded="true"';
    $html .= 'aria-controls="'.$bodyID.'">'.$type;
    $html .= '</a></h4></div>';

    $html .= '<div id="'.$bodyID.'" class="panel-collapse collapse in" ';
    $html .= 'role="tabpanel" aria-labelledby="'.$headingID.'">';

    $html .= '<div class="list-group">';
    foreach ($subTypes as $subType) {
        $target = "tab-".$prefix.$type."-".$subType;
        $html .= '<a href="#'.$target.'" class="list-group-item" ';
        $html .= 'aria-controls="'.$target.'" role="tab" data-toggle="tab"';
        $html .= '>'.$subType.'</a>';
    }

    $html .= '</div></div></div>';
    return $html;
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<style>
.list-group-item.active, .list-group-item.active:hover {
    background-color: white;
    color: black;
}
</style>
</head>
<body>
<div class="container">
<div class="page-header">
    <h1>Configuration Management</h1>
</div>

<div class="row">
    <div class="col-md-5 col-md-push-1 col-sm-6">
        <ul class="nav nav-tabs" role="tablist" id="config-tabs">
            <li role="presentation" class="active">
                <a href="#project_list" aria-controls="project_list" role="tab" data-toggle="tab">
                    <h4>Project</h4>
                </a>
            </li>
            <li role="presentation">
                <a href="#workflow_list" aria-controls="workflow_list" role="tab" data-toggle="workflow_list">
                    <h4>Workflow</h4>
                </a>
            </li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active panel-group" id="project_list" role="tablist" aria-multiselectable="true">
                <?php
                    foreach ($project_types as $type) {
                        echo makeSection( '#project_list', 'project-',$type, $project_subtypes[$type]);
                    }
                ?>
            </div>
            <div role="tabpanel" class="tab-pane panel-group" id="workflow_list" role="tablist" aria-multiselectable="true">
                <?php
                    foreach ($workflow_types as $type) {
                        echo makeSection( '#workflow_list', 'workflow-',$type, $workflow_subtypes[$type]);
                    }
                ?>
            </div>
        </div>
    </div>
    <div class="col-md-5 col-md-push-1 col-sm-6">
        <div id="tabs" class="tab-content" style="padding:0em 0em 0em 1em">
            <?php
                foreach ($project_types as $type) {
                    // @TODO remove once folder structure is all setup
                    if ($type !== 'CD') continue;

                    foreach ($project_subtypes[$type] as $subType) {
                        $html = "<div role ='tabpanel' class='tab-pane'";
                        $html .= "id='tab-project-".$type."-".$subType."'>";
                        $html .= makeInfoSection($type, $subType, $project_versions[$subType], $project_dir);
                        $html .= "</div>";
                        echo $html;
                    }
                }

                foreach ($workflow_types as $type) {
                    foreach ($workflow_subtypes[$type] as $subType) {
                        $html = "<div role ='tabpanel' class='tab-pane'";
                        $html .= "id='tab-workflow-".$type."-".$subType."'>";
                        $html .= makeInfoSection($type, $subType, $workflow_versions[$subType], $workflow_dir);
                        $html .= "</div>";
                        echo $html;
                    }
                }
            ?>
        </div>
    </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="12345" crossorigin="anonymous"></script>
<script type="text/javascript">
    function build (url, params, cb) { 
        url += "/buildWithParameters";

        $.ajax({
            type: 'POST',
            url: url,
            data: params,
            success: cb
        });
    };

    $('.collapse').collapse();

    $('.list-group a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    });

    $('#config-tabs a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    })
</script>
</body>
</html>

.list-group-item.active、.list-group-item.active:悬停{
背景色:白色;
颜色:黑色;
}
配置管理

在php标记启动后放置下面的代码

// check if ajax call
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{    
    // call your php function here and return some data
    $data = someFunction();
    echo json_encode($data);    // return data back in json format, can return in other format as well.
    exit();    // do use exit here otherwise it will return the whole file code 
}

在php标记启动后放置下面的代码

// check if ajax call
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{    
    // call your php function here and return some data
    $data = someFunction();
    echo json_encode($data);    // return data back in json format, can return in other format as well.
    exit();    // do use exit here otherwise it will return the whole file code 
}
试试这个:

<?php
use FW\Config;
require_once 'setup.php';

//Check the get variable for the function being called.
if(isset($_GET['func']) AND function_exists($_GET['func'])){
  $func=$_GET['func'];
  $func();
  //This is an ajax call, we really should exit here so we can let $func handle the ajax output;
   exit;
}
function build($category, $type, $subtype){
   //WANT TO GET HERE
}

function getTypes($dir) {
    return array_diff(scandir($dir), array('..', '.'));
}

function getSubTypes($dir, $type) {
    return array_diff(scandir("$dir//$type"), array('..', '.'));
}

function getVersions($dir, $type, $subType) {
    return array_diff(scandir("$dir//$type//$subType"), array('..', '.'));
}

function getFileContents($dir, $type, $subtype, $file){
    $path = "$dir/$type/$subtype/$file.txt"; 
    $openFile = fopen($path, "r"); 
    $content = fread($openFile, filesize($path)); 
    fclose($openFile);
    return split("/", $content)[0];
}

$project_dir = Config::$appConfig['project_file_dir']['scriptPath'];
$workflow_dir = Config::$appConfig['workflow_file_dir']['scriptPath'];

$project_types = getTypes($project_dir);
$project_subtypes = array();
$project_versions = array();

$workflow_types = getTypes($workflow_dir);
$workflow_subtypes = array();
$workflow_versions = array();

foreach ($project_types as $type) {
    $project_subtypes[$type] = getSubTypes($project_dir, $type);

    //@todo remove once folder structure is all setup
    if ($type !== 'CD') continue;

    foreach ($project_subtypes[$type] as $subType) {
        $project_versions[$subType] = getVersions($project_dir, $type, $subType);
    }
}

foreach ($workflow_types as $type) {
    $workflow_subtypes[$type] = getSubTypes($workflow_dir, $type);

    foreach ($workflow_subtypes[$type] as $subType) {
        $workflow_versions[$subType] = getVersions($workflow_dir, $type, $subType);
    }
}

function makeInfoSection($type, $subType, $versions, $dir) {    

    // list versions
    $html .= '<h4>Available Versions</h4>';
    $html .= '<ul class="list-group">';
    foreach ($versions as $v) {
        if (strpos($v, '.txt')) continue;

        $html .= '<li class="list-group-item">';
        $html .= '<span class="badge"><a href="#" style="color:orange">';
        $html .= '<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"';
        $html .= 'onclick="build()">'; //@todo add onclick to trigger build()
        $html .= '</span></a></span>';
        $html .= $v;
        $html .= '</li>';
    }
    $html .= '</ul>';

    return $html;
}

function makeSection($parent, $prefix, $type, $subTypes) {
    $headingID = 'heading-'.$type;
    $bodyID = 'collapse-'.$prefix.$type;

    $html = '<div class="panel panel-default" style="margin-bottom:10px;">';
    $html .= '<div class="panel-heading" role="tab" id="'.$headingID.'">';
    $html .= '<h4 class="panel-title">';
    $html .= '<a role="button" data-toggle="collapse" data-parent="'.$parent;
    $html .= '" href="#'.$bodyID.'" aria-expanded="true"';
    $html .= 'aria-controls="'.$bodyID.'">'.$type;
    $html .= '</a></h4></div>';

    $html .= '<div id="'.$bodyID.'" class="panel-collapse collapse in" ';
    $html .= 'role="tabpanel" aria-labelledby="'.$headingID.'">';

    $html .= '<div class="list-group">';
    foreach ($subTypes as $subType) {
        $target = "tab-".$prefix.$type."-".$subType;
        $html .= '<a href="#'.$target.'" class="list-group-item" ';
        $html .= 'aria-controls="'.$target.'" role="tab" data-toggle="tab"';
        $html .= '>'.$subType.'</a>';
    }

    $html .= '</div></div></div>';
    return $html;
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<style>
.list-group-item.active, .list-group-item.active:hover {
    background-color: white;
    color: black;
}
</style>
</head>
<body>
<div class="container">
<div class="page-header">
    <h1>Configuration Management</h1>
</div>

<div class="row">
    <div class="col-md-5 col-md-push-1 col-sm-6">
        <ul class="nav nav-tabs" role="tablist" id="config-tabs">
            <li role="presentation" class="active">
                <a href="#project_list" aria-controls="project_list" role="tab" data-toggle="tab">
                    <h4>Project</h4>
                </a>
            </li>
            <li role="presentation">
                <a href="#workflow_list" aria-controls="workflow_list" role="tab" data-toggle="workflow_list">
                    <h4>Workflow</h4>
                </a>
            </li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active panel-group" id="project_list" role="tablist" aria-multiselectable="true">
                <?php
                    foreach ($project_types as $type) {
                        echo makeSection( '#project_list', 'project-',$type, $project_subtypes[$type]);
                    }
                ?>
            </div>
            <div role="tabpanel" class="tab-pane panel-group" id="workflow_list" role="tablist" aria-multiselectable="true">
                <?php
                    foreach ($workflow_types as $type) {
                        echo makeSection( '#workflow_list', 'workflow-',$type, $workflow_subtypes[$type]);
                    }
                ?>
            </div>
        </div>
    </div>
    <div class="col-md-5 col-md-push-1 col-sm-6">
        <div id="tabs" class="tab-content" style="padding:0em 0em 0em 1em">
            <?php
                foreach ($project_types as $type) {
                    // @TODO remove once folder structure is all setup
                    if ($type !== 'CD') continue;

                    foreach ($project_subtypes[$type] as $subType) {
                        $html = "<div role ='tabpanel' class='tab-pane'";
                        $html .= "id='tab-project-".$type."-".$subType."'>";
                        $html .= makeInfoSection($type, $subType, $project_versions[$subType], $project_dir);
                        $html .= "</div>";
                        echo $html;
                    }
                }

                foreach ($workflow_types as $type) {
                    foreach ($workflow_subtypes[$type] as $subType) {
                        $html = "<div role ='tabpanel' class='tab-pane'";
                        $html .= "id='tab-workflow-".$type."-".$subType."'>";
                        $html .= makeInfoSection($type, $subType, $workflow_versions[$subType], $workflow_dir);
                        $html .= "</div>";
                        echo $html;
                    }
                }
            ?>
        </div>
    </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="12345" crossorigin="anonymous"></script>
<script type="text/javascript">
    function build (url, params, cb) { 

        url += "/buildWithParameters";
        //Added so we set the $_GET['func']
        url += "?func=build";

        $.ajax({
            type: 'POST',
            url: url,
            data: params,
            success: cb
        });
    };

    $('.collapse').collapse();

    $('.list-group a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    });

    $('#config-tabs a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    })
</script>
</body>
</html>
试试这个:

<?php
use FW\Config;
require_once 'setup.php';

//Check the get variable for the function being called.
if(isset($_GET['func']) AND function_exists($_GET['func'])){
  $func=$_GET['func'];
  $func();
  //This is an ajax call, we really should exit here so we can let $func handle the ajax output;
   exit;
}
function build($category, $type, $subtype){
   //WANT TO GET HERE
}

function getTypes($dir) {
    return array_diff(scandir($dir), array('..', '.'));
}

function getSubTypes($dir, $type) {
    return array_diff(scandir("$dir//$type"), array('..', '.'));
}

function getVersions($dir, $type, $subType) {
    return array_diff(scandir("$dir//$type//$subType"), array('..', '.'));
}

function getFileContents($dir, $type, $subtype, $file){
    $path = "$dir/$type/$subtype/$file.txt"; 
    $openFile = fopen($path, "r"); 
    $content = fread($openFile, filesize($path)); 
    fclose($openFile);
    return split("/", $content)[0];
}

$project_dir = Config::$appConfig['project_file_dir']['scriptPath'];
$workflow_dir = Config::$appConfig['workflow_file_dir']['scriptPath'];

$project_types = getTypes($project_dir);
$project_subtypes = array();
$project_versions = array();

$workflow_types = getTypes($workflow_dir);
$workflow_subtypes = array();
$workflow_versions = array();

foreach ($project_types as $type) {
    $project_subtypes[$type] = getSubTypes($project_dir, $type);

    //@todo remove once folder structure is all setup
    if ($type !== 'CD') continue;

    foreach ($project_subtypes[$type] as $subType) {
        $project_versions[$subType] = getVersions($project_dir, $type, $subType);
    }
}

foreach ($workflow_types as $type) {
    $workflow_subtypes[$type] = getSubTypes($workflow_dir, $type);

    foreach ($workflow_subtypes[$type] as $subType) {
        $workflow_versions[$subType] = getVersions($workflow_dir, $type, $subType);
    }
}

function makeInfoSection($type, $subType, $versions, $dir) {    

    // list versions
    $html .= '<h4>Available Versions</h4>';
    $html .= '<ul class="list-group">';
    foreach ($versions as $v) {
        if (strpos($v, '.txt')) continue;

        $html .= '<li class="list-group-item">';
        $html .= '<span class="badge"><a href="#" style="color:orange">';
        $html .= '<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"';
        $html .= 'onclick="build()">'; //@todo add onclick to trigger build()
        $html .= '</span></a></span>';
        $html .= $v;
        $html .= '</li>';
    }
    $html .= '</ul>';

    return $html;
}

function makeSection($parent, $prefix, $type, $subTypes) {
    $headingID = 'heading-'.$type;
    $bodyID = 'collapse-'.$prefix.$type;

    $html = '<div class="panel panel-default" style="margin-bottom:10px;">';
    $html .= '<div class="panel-heading" role="tab" id="'.$headingID.'">';
    $html .= '<h4 class="panel-title">';
    $html .= '<a role="button" data-toggle="collapse" data-parent="'.$parent;
    $html .= '" href="#'.$bodyID.'" aria-expanded="true"';
    $html .= 'aria-controls="'.$bodyID.'">'.$type;
    $html .= '</a></h4></div>';

    $html .= '<div id="'.$bodyID.'" class="panel-collapse collapse in" ';
    $html .= 'role="tabpanel" aria-labelledby="'.$headingID.'">';

    $html .= '<div class="list-group">';
    foreach ($subTypes as $subType) {
        $target = "tab-".$prefix.$type."-".$subType;
        $html .= '<a href="#'.$target.'" class="list-group-item" ';
        $html .= 'aria-controls="'.$target.'" role="tab" data-toggle="tab"';
        $html .= '>'.$subType.'</a>';
    }

    $html .= '</div></div></div>';
    return $html;
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<style>
.list-group-item.active, .list-group-item.active:hover {
    background-color: white;
    color: black;
}
</style>
</head>
<body>
<div class="container">
<div class="page-header">
    <h1>Configuration Management</h1>
</div>

<div class="row">
    <div class="col-md-5 col-md-push-1 col-sm-6">
        <ul class="nav nav-tabs" role="tablist" id="config-tabs">
            <li role="presentation" class="active">
                <a href="#project_list" aria-controls="project_list" role="tab" data-toggle="tab">
                    <h4>Project</h4>
                </a>
            </li>
            <li role="presentation">
                <a href="#workflow_list" aria-controls="workflow_list" role="tab" data-toggle="workflow_list">
                    <h4>Workflow</h4>
                </a>
            </li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active panel-group" id="project_list" role="tablist" aria-multiselectable="true">
                <?php
                    foreach ($project_types as $type) {
                        echo makeSection( '#project_list', 'project-',$type, $project_subtypes[$type]);
                    }
                ?>
            </div>
            <div role="tabpanel" class="tab-pane panel-group" id="workflow_list" role="tablist" aria-multiselectable="true">
                <?php
                    foreach ($workflow_types as $type) {
                        echo makeSection( '#workflow_list', 'workflow-',$type, $workflow_subtypes[$type]);
                    }
                ?>
            </div>
        </div>
    </div>
    <div class="col-md-5 col-md-push-1 col-sm-6">
        <div id="tabs" class="tab-content" style="padding:0em 0em 0em 1em">
            <?php
                foreach ($project_types as $type) {
                    // @TODO remove once folder structure is all setup
                    if ($type !== 'CD') continue;

                    foreach ($project_subtypes[$type] as $subType) {
                        $html = "<div role ='tabpanel' class='tab-pane'";
                        $html .= "id='tab-project-".$type."-".$subType."'>";
                        $html .= makeInfoSection($type, $subType, $project_versions[$subType], $project_dir);
                        $html .= "</div>";
                        echo $html;
                    }
                }

                foreach ($workflow_types as $type) {
                    foreach ($workflow_subtypes[$type] as $subType) {
                        $html = "<div role ='tabpanel' class='tab-pane'";
                        $html .= "id='tab-workflow-".$type."-".$subType."'>";
                        $html .= makeInfoSection($type, $subType, $workflow_versions[$subType], $workflow_dir);
                        $html .= "</div>";
                        echo $html;
                    }
                }
            ?>
        </div>
    </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="12345" crossorigin="anonymous"></script>
<script type="text/javascript">
    function build (url, params, cb) { 

        url += "/buildWithParameters";
        //Added so we set the $_GET['func']
        url += "?func=build";

        $.ajax({
            type: 'POST',
            url: url,
            data: params,
            success: cb
        });
    };

    $('.collapse').collapse();

    $('.list-group a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    });

    $('#config-tabs a').click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    })
</script>
</body>
</html>

为什么不为AJAX例程调用一个单独的文件呢

无论如何,要回答您的问题:

AJAX将通过GET或POST向PHP文件发送数据字符串。一个标准化——许多人更喜欢post

正如您所知,AJAX代码块看起来是这样的(您需要发送函数所需的信息):

在PHP文件中,只需捕获该变量:

<?php
    //Your existing PHP file contents go here. At bottom add:

    if ( isset($_POST('var_name') ){
        $category = $_POST('cat');
        $type = $_POST('typ');
        $subtype = $_POST('sub');
        build($category, $type, $subtype);
    }

为什么不为AJAX例程调用一个单独的文件呢

无论如何,要回答您的问题:

AJAX将通过GET或POST向PHP文件发送数据字符串。一个标准化——许多人更喜欢post

正如您所知,AJAX代码块看起来是这样的(您需要发送函数所需的信息):

在PHP文件中,只需捕获该变量:

<?php
    //Your existing PHP file contents go here. At bottom add:

    if ( isset($_POST('var_name') ){
        $category = $_POST('cat');
        $type = $_POST('typ');
        $subtype = $_POST('sub');
        build($category, $type, $subtype);
    }

您应该能够通过URL导航到那里,以便在那里创建http(get/post)。你是吗?如果是,路径是什么?如果不是,你需要在你的应用程序中处理
路由的sth。可能是@MonkeyZeus的副本。我想你可能是对的。很惊讶我没早点发现。看一看,您应该能够通过URL导航到那里,以便在那里生成http(get/post)。你是吗?如果是,路径是什么?如果不是,你需要在你的应用程序中处理
路由的sth。可能是@MonkeyZeus的副本。我想你可能是对的。很惊讶我没早点发现。看一看