Javascript 代码点火器+;$http.post()的角度问题。Codeigniter未接收数据
我有一个奇怪的编码器角度问题。 我的想法是将控制器设置为如下工作方式:Javascript 代码点火器+;$http.post()的角度问题。Codeigniter未接收数据,javascript,php,angularjs,codeigniter,Javascript,Php,Angularjs,Codeigniter,我有一个奇怪的编码器角度问题。 我的想法是将控制器设置为如下工作方式: 索引是简单的角度页面,只有一个应用程序和一个控制器 get是从数据库中获取数据 set用于保存使用$http.post发送的数据 问题是$http.post()发送正确的数据,我在Firebug中看到了它, 但CI不明白这一点 我更改了头参数,试图捕获文件\u获取\u内容(“php://input“和$this->input->post,但始终为Null 有什么想法吗 我试过这个: $http( { method:
- 索引是简单的角度页面,只有一个应用程序和一个控制器
- get是从数据库中获取数据
- set用于保存使用$http.post发送的数据
$http.post()
发送正确的数据,我在Firebug中看到了它,
但CI不明白这一点
我更改了头参数,试图捕获文件\u获取\u内容(“php://input“
和$this->input->post
,但始终为Null
有什么想法吗
我试过这个:
$http(
{
method: 'POST',
url: url,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: data
});
有无标题和转换数据更改。。。什么也没有
更新
我尝试将相同的数据发送到原始php脚本,结果成功了。所以,不知何故,代码点火器阻止了这一点
有什么想法吗?这是一个常见问题,让我们开始: 将脚本添加到文档中 在应用程序模块中,添加此代码
var myApp = angular.module('myApp', ["ngRoute"]).
config(["$httpProvider",function($httpProvider)
{
$httpProvider.interceptors.push(['$q', function($q) {
return {
request: function(config) {
if (config.data && typeof config.data === 'object') {
// Check https://gist.github.com/brunoscopelliti/7492579
// for a possible way to implement the serialize function.
config.data = serialize(config.data);
}
return config || $q.when(config);
}
};
}]);
var serialize = function(obj, prefix) {
// http://stackoverflow.com/questions/1714786/querystring-encoding-of-a-javascript-object
var str = [];
for(var p in obj) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v == "object" ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
return str.join("&");
}
}]).
run(function($http) {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8;";
});
现在在您的邮政服务上(或使用$http的任何地方)
现在codeIgniter将获得输入->post(“数据”)(总是数据) 这是一个常见问题,让我们开始: 将脚本添加到文档中 在应用程序模块中,添加此代码
var myApp = angular.module('myApp', ["ngRoute"]).
config(["$httpProvider",function($httpProvider)
{
$httpProvider.interceptors.push(['$q', function($q) {
return {
request: function(config) {
if (config.data && typeof config.data === 'object') {
// Check https://gist.github.com/brunoscopelliti/7492579
// for a possible way to implement the serialize function.
config.data = serialize(config.data);
}
return config || $q.when(config);
}
};
}]);
var serialize = function(obj, prefix) {
// http://stackoverflow.com/questions/1714786/querystring-encoding-of-a-javascript-object
var str = [];
for(var p in obj) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v == "object" ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
return str.join("&");
}
}]).
run(function($http) {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8;";
});
现在在您的邮政服务上(或使用$http的任何地方)
现在codeIgniter将获得输入->post(“数据”)(总是数据) 尝试过但没有起作用:数据[name]传递名称数据[notes]数据[ranges][0][from]0数据[ranges][0][to]0数据[showRanges]虚假数据[url]http://data[weight_from]0数据[weight_-to]0数据[weight_-to]0在POST中,但在CI端,这需要查看您正在做什么,您能编辑您的帖子并在CI中显示您正在做什么吗?文件获取内容("php://input)也尝试了$this->input->post();当我尝试print_r()时,它会返回Null(第一个)或Array()作为第二个。尝试$this->input->post(“数据”);print_r($_post)Angular 1.5+使用
$http({method:“post”,url:“api/”+apiMethod,headers:{'Content Type':“application/json”},data:data})
尝试过,但不起作用:data[name]Delivery name data[notes]data[ranges][0][from]0 data[ranges][0][to]0 data[showRanges]false data[url]http://data[weight_from]0 data[weight_to]0,但在CI端,这需要查看您正在做什么,您是否可以编辑您的帖子并显示您在CI中正在做什么?文件\u获取\u内容(“php://input)也尝试了$this->input->post();当我尝试print_r()时,它会返回Null(第一个)或Array()作为第二个值。尝试$this->input->post(“数据”);然后打印($_post)Angular 1.5+使用$http({method:“POST”,url:“api/”+apiMethod,头:{'Content Type':“application/json”},data:data})自动解决了这个问题。