【发布时间】:2022-01-06 23:33:27
【问题描述】:
如何处理它们以便我可以使用这两个请求的数据? 用户界面:
async function getSpecialties(){
let res = await fetch ('http://server-npk-web-core/specialties');
let specialties = await res.json();
})
}
async function getSubjectsSpecial(){
let res = await fetch ('http://server-npk-web-core/specialties');
let subjectsSpecial = await res.json();
})
}
BLL: index.php
if($method === 'GET'){
if($type === 'subjects'){
getSubjects($pdo);
} elseif($type === 'specialties'){
getSpecialties($pdo);
getSubjectsSpecial($pdo);
}
specialties.php
function getSpecialties($pdo){
$specialties = 'SELECT * FROM `specialties`';
$stmt = $pdo -> query($specialties);
while ($special = $stmt->fetch()){
$specialtiesList[] = $special;
}
echo json_encode($specialtiesList);
}
function getSubjectsSpecial($pdo){
$subjectsSpecial = 'SELECT `subjects`.`title` FROM `subjects` WHERE `id_specialties` = 2';
$stmt = $pdo -> query($subjectsSpecial);
while ($subjectSpecial = $stmt->fetch()){
$subjectsSpecialList[] = $subjectSpecial;
}
echo json_encode($subjectsSpecialList);
}
附:别拿棍子打我,我是自学的-_-
【问题讨论】:
-
创建另一个异步函数并等待提供的两个函数?
-
两个请求当前看起来相同。为每个请求使用查询字符串参数,以便后端脚本可以调用相应的函数并发送适当的响应
标签: javascript php api