我有这样的列表
John
Jack
Husam
Koko
Rami
Loay
我有下拉列表它也有所有这些名字,当我输入Rami的id例如在URL中他在下拉列表中选择了选项时,我想如果我在URL中输入Rami的ID使他的父母(科科)选择的选项不是拉米。我构建函数来获取父ID及其工作如何从ajax调用它并获取id的父ID我在URL中输入
PHP
public function getParentId($childId)
{
$statment = $this->db->prepare("SELECT parent FROM `person` WHERE id = $childId");
$statment->execute();
$result = $statment->fetchAll();
foreach($result as $output){
return $output['parent'];
}
}
这是我的ajax
if ($object->getParentId(($_GET['childId']))){
echo "<script>
$(document).ready(function(){
$.ajax({
type: 'GET',
url: 'http://test.local/Family.php?action=getId&childId=idd',
data: {'idd' : $_GET[childId]},
success: function(msg) {
document.getElementById('names').value = $_GET[childId];
}
});
}); </script>";
}
答案 0 :(得分:1)
我改变了这部分
if ($object->getParentId(($_GET['childId']))){
echo "<script>
$(document).ready(function(){
$.ajax({
type: 'GET',
url: 'http://test.local/Family.php?action=getId&childId=idd',
data: {'idd' : $_GET[childId]},
success: function(msg) {
document.getElementById('names').value = $_GET[childId];
}
});
}); </script>";
}
对此及其工作
if ($object->getParentId(($_GET['childId']))){
echo "<script>
$(document).ready(function(){
$.ajax({
type: 'GET',
url: 'http://test.local/Family.php?action=getId',
data: {'childId' : $_GET[childId]},
success: function(msg) {
document.getElementById('names').value = msg;
}
});
}); </script>";
}