i executing post request angular js against java servlet running on google app engine. code works fine, unfortunately i've noticed if 1 (or more) parameters long following error:
error: length required
post requests require content-length header.
this angular js code:
app.controller('mycontroller', ['$scope', '$http', '$log', function($scope,$http,$log) { this.myfunction = function() { $http({ method: 'post', url: '/myservlet', params: { method: 'my_method', param1 : $("#param1").val(), param 2: ... } }).success(function(data) { }).error(function(data) { }); }; }
param1, param2 etc different fields, textarea though. suggestion? don't know do.
edit: tried setting content-length in header myself error expected...
headers : { 'content-length' : 0 },
refused set unsafe header "content-length"
so basically, if set content-length browser refuses execute call, if don't set server says it's required... can do?
the params
argument using used pass variables as part of url when method
post ($http docs). pass information in body of post request have use data
argument.
so, request should be:
$http({ method: 'post', url: '/myservlet', data: { method: 'my_method', param1 : $("#param1").val(), param 2: ... } }).success(function(data) { }).error(function(data) { });
Comments
Post a Comment