My controller class like that.
@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();
}
The above code create the List data. I want to pass above list data using ajax call.
My ajax method like that.
$.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
}
});
But above mJSONArray
is string type. I want to get Json type. I don't know how I create it.
my chartData array like that.
[[stageViiChartDataModal: Updated_Scope = Ericsson, Dependency = WIP, On_Air_date = 4-Dec-15], [stageViiChartDataModal: Updated_Scope = Ericsson, Dependency = WIP, On_Air_date = 9-Dec-15]]
Just do..
success: function (mJSONArray) {
var d = JSON.parse(mJSONArray);
alert(d);
},
Change your Content-Type Content-Type: application/json
then you can pass json arral list data.
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.