【发布时间】:2014-01-28 05:28:51
【问题描述】:
我有以下脚本。此脚本位于 JSP 中,其中一个接一个地填充了 Country、State 和 Cities 组合框(级联选择)
The script is suppose to fetch the data from the controller and populate list of states for the country selected. The function is called alert("inside ajax") is displayed and calls the controller method too. The controller fetches the list of states sucessfully and returns the list of states as "Set". when the control is passed back to the json alert("received data") doesnot pop up and nothing happens after that. There are no errors displayed too.
I have "json-lib-2.4-jdk15.jar" in my library. Do I need any more settings? or what is that I'm missing?
jason java脚本如下
<script type="text/javascript">
$(document).ready(function() {
$('#countryName').change(
function() {
alert("inside ajax");
$.getJSON('${findStateURL}', {
countryName : $(this).val(),
ajax : 'true'
}, function(data) {
alert("received data");
alert(data);
var html = '<option value="">State</option>';
var len = data.length;
alert(len);
for ( var i = 0; i < len; i++) {
html += '<option value="' + data[i].name + '">'
+ data[i].name + '</option>';
alert(html);
}
html += '</option>';
$('#states').html(html);
});
});
});
我调用的控制器方法是
@Controller
public class CountryController {
@Autowired
private CountryService countryService;
@RequestMapping(value = "/getStates.htm", method = RequestMethod.GET)
@ResponseBody public
Set<State> StatesForCountry(
@RequestParam(value = "countryName", required = true) String countryName, Map<String, Object> map) {
System.out.println("countryName " + countryName);
System.out.println("Country Id ");
List<State> states = countryService.getAllStates(countryName);
Set<State> state_set = new HashSet<State>(states);
System.out.println(" no. of states set = " + state_set);
return state_set;
}
控制器正在返回“集合”中所需的值。但唯一的问题是我没有收到任何数据 alert("收到数据");
【问题讨论】:
标签: javascript ajax json spring jackson