I have a problem here.
I have been using $resource to do simple GET, but recently i have a large amount of data to send to the server, but gives a 414 Error URI too large. I know that one of the solution is to use POST instead of GET.
I tried to search for solutions such as $http.post and passing parameters to $http, but to no avail. Can someone give me a tutorial on how should i do it?
Edit:
Here is what i have done:
var data_2 = $.param({'method':"update_proj",
'proj_id': proj_id,
'ptitle': project.title,
'pdescription': p_desc,
'pexposure': tech,
'pcompany': project.company,
'pteamsize':project.teamsize,
'ppoc': project.poc,
'pemail': c_email,
'pcontact': project.contact,
'pimg':project.img,
'pvideo':project.video,
'prskill': rskills,
'poutcome': project.outcome});
$http({method:'update_proj',
url: "http://osmosisgal.appspot.com/update_proj",
data: data_2,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
.success(function(data,status){
...
});
Here is my python code on GAE:
class ActionHandler(webapp.RequestHandler):
def update_project(self):
proj_id = self.request.POST["proj_id"]
.
.
.
But i still have this error
Traceback (most recent call last):
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~osmosisgal/1.366101252356646323/new_backend.py", line 1274, in update_project
proj_id = self.request.POST["proj_id"]
File "/python27_runtime/python27_lib/versions/third_party/webob-1.1.1/webob/multidict.py", line 312, in __getitem__
return self._decode_value(self.multi.__getitem__(self._encode_key(key)))
File "/python27_runtime/python27_lib/versions/third_party/webob-1.1.1/webob/multidict.py", line 568, in __getitem__
raise KeyError("No key %r: %s" % (key, self.reason))
KeyError: "No key 'proj_id': Not a form request"
From documentation you can see that method is getting the type of method and not the url, in first place.
$http({method: 'POST', url: '/someUrl', data: my_data}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
For you data you can create a json object with pairs, key-value and pass it to the function like above.
Also do not forget to pass $http in your controller definition.
function MyController($scope, $http) {...};
I managed to solve it. Initially I did not host all my static files in GAE, after i hosted it, everything works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.