Reputation: 301
Hi I have written a rest service using the Spring framework Below is the code. It returns Json appropriately.
@ResponseBody
@RequestMapping(value="/showProcessUsage/" ,method=RequestMethod.GET)
public SystemProcessInfo getASingleProcessInfo()
{
String processName="chrome" //hard coded just for trials;
SystemProcessInfo processInfo ;
processInfo = processInfoService.getASingleProcessUsage(processName);
return processInfo;
}
In the Html I am trying to make an ajax call, but it is failing below is the call
$.ajax({
type: "GET",
dataType: "json",
headers: {
Accept:"application/json",
"Access-Control-Allow-Origin": "*"
},
url: "/PerformanceMonitor/showProcessUsage/",
success: function(data){
alert("HI");
alert(data);
alert("HI");
}
});
Upvotes: 1
Views: 1084
Reputation: 2837
There a number of code issues where it could fail:
First, Your rest service endpoint expects a
@PathVariable("processName")
which I don't think you are passing in the AJAX call.
try with the following line
url: "/PerformanceMonitor/showProcessUsage/xyz-process"
Secondly, your Spring controller method should contain the pathVariable defined in the annotation:
@RequestMapping(value="/showProcessUsage/{processName}"
For debugging:
put an error block in your ajax call.
error: function(response){
alert(response);
}
Upvotes: 1
Reputation: 301
Thee js file for jquery that I included was corrupt .. I tried using the google cdn for jquery and it worked fine for me. Thanks for your time :)
Upvotes: 0