Hi All I am working in a PHP project. I am stucked with an issue related with Ajax.
Kimin seçim bölümü ajax kullanarak görüntülenir üzerinde, ve ben kullanıcıların listesini almak başka bir kullanıcı grubu seçin kutusunda birlikte departmanı seçim kutusunu bölüm seçimi Company için bir seçme kutusu var.
Şimdi Kullanıcı grubundaki değişikliği ben kendi kullanıcıları almak için kullanıcı grup kimliği ve bölüm id gibi ajax kullanarak sunucuya isteği gönderin. Bu bölüm liste ajax ve Ajax Javascript kolu yok oluşturulur Ama ben departmanı yeniden seçmek zaman ben yeni kullanıcı listesini alınamıyor.
Ben ile çalışıyorum Kodu:
select box to select company
<select name="companyname" id="companyname" onchange="javascript:dochange(this.value);">
<option value="-1">-----Select Company-----</option>
<?php foreach($user_obj->getUserCompanyname() as $key => $value){
$selected = '';
if($value['company_id'] == $user_obj->user_company_id){
$selected = 'selected="selected"';
}
?>
<option value="<?php echo $value['company_id'];?>"
<?php echo $selected;?>><?php echo $value['company_name'];?></option>
<?php }?>
Javascript to execute ajax
<script>
//Inint_AJAX funnction is excluded as it has to do anything with requirement
function dochange(val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById('selectdepartment').innerHTML="";
document.getElementById('selectdepartment').innerHTML=req.responseText; //retuen value
}
}
};
req.open("GET", "company.php?val="+val); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}
</script>
company.php
$val=$_GET['val'];
echo "<select name='departmentname' id='departmentname'>\n";
echo "<option value='-1'><b>Select Department</b></option>\n";
foreach($user_obj->getUserDepartmentname($val) as $k=>$vals){
echo "<option value='".$vals['department_id']."'>".$vals['department_name']."</option>";
}
echo "</select>\n<br>";
echo " <span class='asterisk>NOTE:Please (Re)Select the User Group everytime you change department.</span>";
User Group Select Box
<select name="usergroupname"
onchange="javascript:dochangereport(this.value,document.getElementById('departmentname').value);
dochangeoverride(this.value,document.getElementById('departmentname').value);" id="usergroupname">
<option value="-1">Select User Group</option>
<?php
foreach($user_obj->getUserGroupName() as $gkey=>$gval){
$gselect = '';
if($gval['usergroup_id'] == $user_obj->user_group_id){
$gselect = 'selected="selected"';
}
?>
<option value="<?php echo $gval['usergroup_id'];?>"
<?php echo $gselect;?>><?php echo $gval['usergroup_name'];?>
</option>
<?php }?>
</select>
function calling ajax call
<script>
function dochangereport(val,dep) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById('selectreport').innerHTML="";
document.getElementById('selectreport').innerHTML=req.responseText; //retuen value
}
}
};
req.open("GET", "reportto.php?val="+val+"&dep="+dep); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}
</script>
**reportto.php**
$val=$_GET['val'];
$dep=$_GET['dep'];
echo "<select name='reportingto[]' multiple='multiple' size='3'>\n";
echo "<option value='-1'><b>Select Supervisor(s)</b></option>\n";
foreach($user_obj->getUserReportingto($val,$dep) as $rkey=>$rval){
echo "<option value='".$rval['user_id']."'>".$rval['user_fname']." ".$rval['user_fname']." </option>";
}echo "</select>\n";
Birisi bu bana yardımcı olabilir?