如何使用ajax调用获取数组列表数据(将数组列表数据控制器传递给ajax方法)
How to get array list data using ajax call (pass array list data controller to ajax method)
我的控制器类就是这样。
@RequestMapping(value = {"/ajaxcallabd"}, method = RequestMethod.POST)
@ResponseBody// <== this annotation will bind Arr class and convert to json response.
String addAnotherAppointmenttt(HttpServletRequest request, HttpServletResponse response, @RequestBody String userJson, Model model, BindingResult errors) {
System.out.println("*******88888" + userJson);
List<stageViiChartData> chartData = stageViiChartDataServices.findBystageViiChaData(userJson);
return chartData.toString();
}
上面的代码创建了List数据。我想使用ajax调用传递上面的列表数据。
我的ajax方法就是这样。
$.ajax({
type: "POST",
url: "/MobitelProgressTool/ajaxcallabd",
data: userJson,
contentType: "application/json; charset=utf-8",
// dataType: 'JSON',
datatype:'text',
success: function (mJSONArray) {
alert(mJSONArray);
},
failure: function (erroes) {
alert(erroes + ">>>>>");//handle it in a proper way
}
});
但mJSONArray
以上是字符串类型。我想要Json型。我不知道我是怎么创建的。
我的chartData数组就是这样。
[[stageViiChartDataModal: Updated_Scope = Ericsson, Dependency = WIP, On_Air_date = 4-Dec-15], [stageViiChartDataModal: Updated_Scope = Ericsson, Dependency = WIP, On_Air_date = 9-Dec-15]]
只需执行..
success: function (mJSONArray) {
var d = JSON.parse(mJSONArray);
alert(d);
},
更改内容类型Content-Type: application/json
,然后可以传递json数组列表数据。
public class AppConfig extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.ignoreAcceptHeader(true).defaultContentType(MediaType.TEXT_HTML);
configurer.ignoreAcceptHeader(true).defaultContentType(MediaType.APPLICATION_JSON);
}
相关文章:
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 使用图像数组列表的simplegallary.js显示适合桌面屏幕的图像
- 从多维嵌套json数组创建下拉列表
- 如何发送分配列表<字符串>到JavaScript数组或可枚举对象
- Jquery 读取编号组中选择下拉列表的数组
- 如何从 URL 数组向文档添加图像列表
- 为对象数组创建列表项
- 从javascript中的数组列表中获取值
- 从select创建项目列表/数组
- 列表/数组的迭代问题
- 列表/数组是否有效 JSON
- 如何在C# MVC的VIew中将列表数组拆分为单独的数组
- 对列表/数组中的每个项目运行相同的函数
- 需要 JQuery 标记从数据库的列表/数组中选中的复选框
- javascript indexOf - 列表/数组中的完全匹配
- PHP 从现有代码中随机化文件列表数组
- 使用自定义函数从字典中创建列表/数组
- 检查元素是否具有在列表/数组中给定的类
- html中的下拉列表数组
- 如何在javascript中读取对象文件列表数组