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
Release: 2023-03-04 18:50:02
Original
3105 people have browsed it

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>
Copy after login

$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);
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template