I am getting this is the error I get in browser.
XMLHttpRequest cannot load http://ift.tt/1FfvVmZ. No 'Access-Control-Allow-Origin' header is present on the requested resource.
To solve this how can i set headers for CORS in my controller functions. `
@RequestMapping(value = "/getlist", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody JSONArray geResourceList(){
logger.info("getAllResources() from ajax begins: ");
Map<String, String> resourceMap = null;
JSONArray map = new JSONArray();
try {
List<ResourceModel> resourceList = resourceService
.getAllResources();
java.util.Iterator<ResourceModel> resourceIterator = resourceList.iterator();
while (resourceIterator.hasNext()) {
resourceMap = new HashMap<String, String>();
ResourceModel model = resourceIterator.next();
resourceMap.put("resourceType", "" + model.getResourceType());
resourceMap.put("name", "" + model.getName());
map.add(resourceMap);
}
} catch (Exception e) {
logger.debug("Error while getting location in ajax request:"
+ e.getMessage());
e.printStackTrace();
}
}`
The following is my angular code where i get response.
var app = angular.module('myApp', []);
app.controller('Hello', function($scope, $http) {
$http.get('http://ift.tt/1FfvVn1').
success(function(data) {
$scope.response = data;
});
});
Aucun commentaire:
Enregistrer un commentaire