This is my angular js code in which i want to send data in Json format to my restful web service written in java. It makes call to the webservice but i don't get any data.
<script>
var app = angular.module("myPost", []);
app.controller("myControl", function ($scope, $http) {
$scope.title = "",
$scope.rating = "",
$scope.feedback = "",
$scope.role = "";
$scope.send = function (title, rating, feedback, role) {
var feed = {
title: title,
rating: rating,
feedback: feedback,
role: role
};
var head = {'Content-Type': 'application/json'};
$http({
method: 'POST',
url: 'myurl',
data: feed,
headers: head
}).success(function (data, status, headers, config) {
$scope.users = data;
}).error(function (data, status, headers, config) {
$scope.error = status;
});
};
});
</script>
</head>
<body ng-app="myPost" ng-controller="myControl">
<form action="">
Title: <input type="text" name="title" value="" ng-model="title" />{{title}}<br>
Rating:<br> <select name="rating" ng-model="rating">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select><br>
Feedback: <input type="text" name="feedback" value="" ng-model="feedback"/><br>
<input type="hidden" name="type" value="article" ng-model="role" />
<input type="submit" ng-click="send(title, rating, feedback, role)" value="submit" />
This is my restful Web Service where I want the data.
@Path("/database")
public class database {
@Path("/insert")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String insert(@QueryParam("title") String title,
@QueryParam("rating") int rating,
@QueryParam("feedback") String feedback,
@QueryParam("role") String role) {
Data d = new Data();
d.setTitle(title);
d.setRating(rating);
String response = new Gson.toJson(d);
}
return response; }
responsevariable ?