Home >Backend Development >PHP Problem >What is the method for js to call php files?

What is the method for js to call php files?

coldplay.xixi
coldplay.xixiOriginal
2020-08-19 10:19:503084browse

The method for js to call php files: first create a new php file; then use [$cid_data] to process it at the top of the file php code, the code is [$cid_data .= "'".$item['name' ]."'";】.

What is the method for js to call php files?

The method of js calling php file:

Implement the function

There is a button and a The input box input box input button is clicked to execute the php code

Baidu has found for a long time that form submission is the most reasonable

<div id="side-tab3">
            <h2>批量获取数据</h2>
            <p>根据cid 获取所有商品名称</p>
            <form action="admin.php#side-tab3" id="form_get_all_name" method="post">
                <input type="text" id="cid_all_name" name="cid_all_name">
                <button class="btn btn-success cid_all_name">获取</button>
            </form>
            <div>
                <?php echo $cid_data ?>
            </div>
        </div>

$cid_datacan be processed at the top of the file php code

function getCidAllNamme($con, $name)
{
    $sql = "select `name` from `la_goods` where `cid`=&#39;{$name}&#39;";
    if (!$obj = mysqli_query($con, $sql)) {
        die(mysqli_error($con) . $sql);
    }
    $nameList = array();
    while ($res = mysqli_fetch_assoc($obj)) {
        $nameList[] = $res;
    }
    $cid_data = &#39;&#39;;
    if (count($nameList) > 0) {
        $cid_data .= "[&#39;";
        //python 中数组的表示方法  [&#39;&#39;,&#39;&#39;]
        foreach ($nameList as $item) {
            $cid_data .= "&#39;".$item[&#39;name&#39;]."&#39;";
        }
        $cid_data .= "&#39;]";
    }
    return $cid_data;
}
 
$cid_all_name = $_POST[&#39;cid_all_name&#39;];
if (!empty($cid_all_name)) {
    $cid_data = getCidAllNamme($con, $cid_all_name);
}

Related learning recommendations: php programming (video)

The above is the detailed content of What is the method for js to call php files?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn