这是我的ajax调用
<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>
这是我的 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'];
?>
我不知道我在代码中哪里犯了错误,但似乎我无法访问 json 响应。我已经尝试了不同的方法,我还在学习这个 ajax 和 json,所以我很难看出我在哪里犯了错误