我似乎无法理解 ajax 和 json
我想做一个级联下拉菜单,我试图将数据放到一个 div 开始。这是脚本
<script src="~/Scripts/jquery-ui-1.8.20.js"></script>
<script src="~/Scripts/jquery-ui-1.8.20.min.js"></script>
<script>
$(function () {
$('#funtiontype').change(function () {
var selectedValue = $(this).val();
$.ajax(
{
// url: $(this).data('url'),
// source: "/EmployeeReps/GetDescription",
url: "~/EmployeeReps/GetDescription",
type: 'GET',
cache: false,
data: {value: selectedValue },
success: function (result) {
$('#description').html(result.employeelist);
}
});
});
});
</script>
和控制器
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult GetDescription(string value)
{
//get the data from DB
var employeelist =(from s in db.tble_employeeReps where s.em_function==value
select s);
return Json(employeelist.ToList(), JsonRequestBehavior.AllowGet);
}
HTML @using (Html.BeginForm()) {
<fieldset>
<div class="editor-label">Function*</div>
<div class="editor-field">
<select id = "funtiontype">
<option value = "">Please Select</option>
<option value = "Finance">Finance</option>
<option value = "Non-Finance">Non-Finance</option>
</select>
</div>
<p></p>
<p>
<input type="submit" value="Vote" />
</p>
</fieldset>
<div id="description"></div>
}
但我正在努力获取任何数据。请任何人都可以帮助
非常感谢提前赫什