AngularJS – $http.post发送数据为json

前端之家收集整理的这篇文章主要介绍了AngularJS – $http.post发送数据为json前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用angularjs自动完成指令,但有一些问题。

我有一个具有自动完成输入的表单。当我在那里键入内容时,变量一词作为JSON发送:

但是,当我使用相同的功能(从不同的角度控制器,但相同的功能)在另一种形式术语变量发送完美,自动完成工作正常:

这里是我的角函数

  1. $scope.getCustomers = function (searchString) {
  2. return $http.post("/customer/data/autocomplete",{term: searchString})
  3. .then(function (response) {
  4. return response;
  5. });
  6. };@H_502_8@
  7. 你觉得怎么样?

使用JSON.stringify()来包装你的json
  1. var parameter = JSON.stringify({type:"user",username:user_email,password:user_password});
  2. $http.post(url,parameter).
  3. success(function(data,status,headers,config) {
  4. // this callback will be called asynchronously
  5. // when the response is available
  6. console.log(data);
  7. }).
  8. error(function(data,config) {
  9. // called asynchronously if an error occurs
  10. // or server returns response with an error status.
  11. });@H_502_8@

猜你在找的Angularjs相关文章