try
var reponsedata=JSON.parse(response); alert("IntentionDetails : "+ responsedata.results);
質問
I'm making an AJAX call using JQuery and Spring MVC.
The client script :
$.ajax({
type : "POST",
url : "channelIntentionDetails.html",
data : stringifiedSearchParameter,
beforeSend : function(
xhr) {
xhr
.setRequestHeader(
"Content-Type",
"application/json");
},
success : function(
response) {
alert("IntentionDetails : "
+ response.results);
if (jQuery
.isEmptyObject(response)) {
alert("No data found for");
}
drawIntentionPieChart(response.results);
}
});
The controller method :
@RequestMapping(value = "channelIntentionDetails.html", method = RequestMethod.POST)
public @ResponseBody
com.lnt.sapphire.pojo.Report getChannelIntentionDetails(@RequestBody SearchParameters searchParameters) {
System.out.println("In ReportController.getChannelIntentionDetails(...), searchParameters " + searchParameters);
com.lnt.sapphire.pojo.Report report = channelDetailsService.getIntentionDetails(searchParameters);
System.out.println("Returning from ReportController.getChannelIntentionDetails(...), report " + report);
return report;
}
The Report POJO :
public class Report {
private Map<String, Collection<String>> parameterWiseResult;
private Collection<String> results;
private String result;
public Map<String, Collection<String>> getParameterWiseResult() {
return this.parameterWiseResult;
}
public Collection<String> getResults() {
return this.results;
}
public void setParameterWiseResult(
final Map<String, Collection<String>> parameterWiseResult) {
this.parameterWiseResult = parameterWiseResult;
}
public void setResults(final Collection<String> result) {
this.results = result;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
@Override
public String toString() {
return "Report [parameterWiseResult=" + parameterWiseResult
+ ", results=" + results + ", result=" + result + "]";
}
}
The output on the server console(results is an array) :
Returning from ReportController.getChannelIntentionDetails(...), report Report [parameterWiseResult=null, results=[{ "_id" : { "SpId" : 664 , "Intention_category" : "" , "Report_Id" : 2 , "Channel_Id" : 1} , "count" : 10}], result=null]
But the response I get in the script(check the alert for response.results) :
{ "_id" : { "SpId" : 664 , "Intention_category" : "" , "Report_Id" : 2 , "Channel_Id" : 1} , "count" : 10}
Now this is causing a problem on parsing - the array[] is gone !
Any hints?
正しい解決策はありません
他のヒント
try
var reponsedata=JSON.parse(response); alert("IntentionDetails : "+ responsedata.results);