Having this GET request, it works (sends request to the sever and server is able to handle it):
/* post to server*/
$http.get("/forms/FormValidator1/validateForm/" + JSON.stringify(data)).
success(function(data) {
console.log("good")
}).
error(function(data, status, headers, config) {
console.log("something wrong")
})
When I use this POST request it doesn't.
$http.post("/forms/FormValidator1/validateForm/" + JSON.stringify(data)).
success(function(data) {
console.log("good")
}).
error(function(data, status, headers, config) {
console.log("something wrong")
})
or writing in different form:
$http({
url: '/forms/FormValidator1/validateForm',
method: "POST",
data: JSON.stringify(data),
headers: {'Content-Type': 'application/json'}
}).success(function (data, status, headers, config) {
console.log("good")
}).error(function (data, status, headers, config) {
console.log("something wrong")
});
What I have in the end is:
Request URL:http://localhost:9000/forms/FormValidator1/validateForm
Request Method:POST
Status Code:404 Not Found
Requested payload is json: {"name":"name1","surname":"surname1"}
On the server (playframework) I defined routes that are supposed to accept client calls.
GET /forms/FormValidator1/validateForm/:jsonForm controllers.FormValidator1.validateForm(jsonForm:String)
POST /forms/FormValidator1/validateForm/:jsonForm controllers.FormValidator1.validateForm(jsonForm:String)
Or with no ":jsonForm"
POST /forms/FormValidator1/validateForm controllers.FormValidator1.validateForm(jsonForm:String)
What might be the reason. What I missed?
UPDATE
Interestly enough: after I got it working on my laptop (see my answer below) then push it on gitHub and pull it to another machine it starts working differently. Now it complains than Bad Request is [Invalid XML] nevertheless I use "application/json"
header and did not change any line of code after commit. I wonder maybe it is a bug.
It seems along DocumentType
, I need provide dataType : 'json'
, but since Play wants it be in the url. This all does not work.