Home >Backend Development >PHP Problem >What is the method for js to call php files?
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' ]."'";】.
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_data
can be processed at the top of the file php code
function getCidAllNamme($con, $name) { $sql = "select `name` from `la_goods` where `cid`='{$name}'"; if (!$obj = mysqli_query($con, $sql)) { die(mysqli_error($con) . $sql); } $nameList = array(); while ($res = mysqli_fetch_assoc($obj)) { $nameList[] = $res; } $cid_data = ''; if (count($nameList) > 0) { $cid_data .= "['"; //python 中数组的表示方法 ['',''] foreach ($nameList as $item) { $cid_data .= "'".$item['name']."'"; } $cid_data .= "']"; } return $cid_data; } $cid_all_name = $_POST['cid_all_name']; 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!