this is my ajax call
<script src = "js/jquery.js" type = "text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#DepartmentNameDropdown').change(function(){
$('#DepartmentName').attr('value', document.getElementById("DepartmentNameDropdown").options[document.getElementById("DepartmentNameDropdown").selectedIndex].text);
$.ajax({
type: "POST",
dataType: "json",
url: "http://localhost:8081/crownregency/getInfo.php",
data: {id : $('#DepartmentNameDropdown').val()}, //data: {status: status, name: name},
success:function(data){
$('#DepartmentDescription').attr('value', data.Desc);
}
});
});
});
$('#DepartmentName').attr('value', $('#DepartmentNameDropdown').text());
</script>
this is my getinfo.php
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("jkings");
$value = $_POST['id'];
$query = mysql_query("SELECT * FROM department WHERE dept_ID = $value");
$row = mysql_fetch_array($query);
$desc = $row['dept_desc'];
$mission = $row['dept_mission'];
$struct = array('Desc' => '$desc', 'Mission' => '$mission');
session_start();
$_SESSION['id'] = $value;
echo json_encode($struct);
//echo $row['dept_desc'];
?>
I do not know where in the code i made a mistake but it seems i can’t access the json responds. i have tried different ways to this, i am still learning this ajax and json so it is hard for me to see where i made a mistake
I’m not entirely sure, but I think you might have to change
into
Also,
should be changed to