【发布时间】:2016-07-26 06:25:03
【问题描述】:
在我的程序中,我需要通过传递 id 来执行操作。id 是从下拉框中选择的(即;动态更改)。所以要传递 id,我正在使用 ajax。但我不知道代码在春天接收来自控制器的响应。
<div class="form-group">
<label class="col-sm-4 control-label">Employee</label>
<div class="col-sm-6">
<select id="empId" name="empId" class="form-control" >
<option value="" >--Select--</option>
<c:forEach var="row" items="${employeeList}" >
<option value="${employeeList.Id}">${employeeList.name</option>
</c:forEach>
</select>
</div>
<div class="col-sm-6">
<input type="text" name="empname" id="empname" class="form-control"/>
</div>
</div>
//i need to pass the employee id from the dropdown box to controller and get //the name of the employee as response .and set the response value in the text //box.how can be it done in spring using ajax.
//我试过的ajax代码
$('#empId').change(function(event) {
var eId= $("select#empId").val();
$.get('getEmpName', {
id: eId
}, function(data) {
$('#empname').val(data);
});
});
//but i am not getting any response ie:nothing in data
【问题讨论】:
-
你想如何通过ajax调用控制器,以及控制器方法是什么?我的意思是 ajax 调用和控制器端代码?
-
@Ataur Rahman Munna:是的
-
我粘贴了一些示例代码。如果这有帮助,请接受答案。谢谢。
-
@Ataur Rahman Munna 粘贴的代码很有用。谢谢
-
然后你可以点击接受按钮接受我的回答。 :)
标签: java ajax spring-mvc