angular.js$http.post将数据发送到Rails4
angular.js $http.post sends data to Rails 4
当我从angular发出创建会话的后期请求时
$http.post('http://localhost:3000/api/v1/sessions',
{
email: $scope.email,
password: $scope.password
}).success(function(data, status, headers, config) {
console.log(data);
console.log(status);
}).error(function(data, status, headers, config) {
console.log(status);
});
};
它以JSON形式接收,但params在rails中转换为哈希,那么如何获取电子邮件和密码的值呢?
Started POST "/api/v1/sessions" for 127.0.0.1 at 2015-02-25 21:21:56+0530
Processing by Api::V1::SessionsController#create as JSON
Parameters: {"{'"email'":'"hello@example.com'",'"password'":'"somepassword123'"}"=>"[FILTERED]"}
正如我现在看到的params内容-它是
"{'"email'":'"hello@example.com'",'"password'":'"somepassword123'"}"=>"[FILTERED]"}"
提前谢谢。
这应该会有所帮助:
$http({
url: 'http://localhost:3000/api/v1/sessions',
dataType: 'json',
method: 'POST',
data: {
email: $scope.email,
password: $scope.password
},
headers: {
"Content-Type": "application/json"
}
}).success(function(response){
// do something
}).error(function(error){
// do something
});
我使用jQuery:解决了我的问题
var myDataOfServer = $.param({'disappeared':{
name:$scope.data.name ... }
$.param
负责为服务端解析JSON的原因。
是否需要在angular中为ruby实现模块?
我的服务器Ruby是一个Web服务。
我的IONIC是客户。。。
我的createhttp.post方法是这样做的:
参数:{"{''"name ''":''"ola mundo ''"}"=>nil}
但应该是:
参数:{"utf8"=>"✓","authenticity_token"=>"l916wPHn7wvf0LzEPclKBHALEE7j9KjyiUc5aMpatSFqyQGsmCLwN9ByT8gpwrcrEgC3MLRcafQWSc3V6bvAZA==","消失"=>{"name"=>"nome"},"commit"=>"已保存"}
相关文章:
- 用程序搜索JQuery数据表中的文本
- 要求输入在数据列表中
- 正在将数据主题添加到所有项目
- 函数参数中的数据与指定变量之间的任何性能差异
- 在VanillaJS中模拟模型双向数据绑定
- CSS-如何定位内容数据标题
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 序列化数据属性中对象的最可靠方法
- 如何将JSON数据导入我的ejs模板
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- 画布数据到图像
- 使用jquery将mysql数据获取到新的表行中
- 使用html中的外部javascript进行数据验证
- 有时数据是't显示在浏览器中
- React中的数据集表示
- Angular只从数组中获取所需的数据
- angular.js$http.post将数据发送到Rails4
- Rails4-如何通过Ajax安全地接收和发送JSON数据并进行存储