AngularJS - $ http.post发送数据作为JSON [英] AngularJS - $http.post send data as json
本文介绍了AngularJS - $ http.post发送数据作为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的工作自动完成指令与angularjs但有一些问题。
I'm working on autocomplete directive with angularjs but having some issues.
我有有一个自动完成输入的形式。当我输入的东西在那里,在长期变量被作为JSON:
I have a form which have an autocomplete input. When i type something there, the term variable is sent as JSON:
但是,当我以另一种形式使用相同的功能(从不同的角度控制器,但同样的功能)在长期变量发送完美,自动完成正常工作:
But, when i use the same function (from different angular controller, but the same function) in another form the term variable sent perfectly and the autocomplete works fine:
下面是我的角度功能:
$scope.getCustomers = function (searchString) {
return $http.post("/customer/data/autocomplete",
{term: searchString})
.then(function (response) {
return response;
});
};
你认为什么是错的?
What do you think is wrong?
推荐答案
使用JSON.stringify()来包装你的JSON
Use JSON.stringify() to wrap your json
var parameter = JSON.stringify({type:"user", username:user_email, password:user_password});
$http.post(url, parameter).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
console.log(data);
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
这篇关于AngularJS - $ http.post发送数据作为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文